使用pip安装TensorFlow 相关问题
0. 前言
TensorFlow 2 軟件包現已推出
- tensorflow:最新穩定版(適用于 Ubuntu 和 Windows),**支持 CPU 和 GPU **(CPU、GPU版本已經合并)
- tf-nightly:預覽 build(不穩定)。Ubuntu 和 Windows 均包含 GPU 支持。
舊版 TensorFlow
- 對于 TensorFlow 1.x,CPU 和 GPU 軟件包是分開的:
- tensorflow==1.15:僅支持 CPU 的版本
- tensorflow-gpu==1.15:支持 GPU 的版本(適用于 Ubuntu 和 Windows)
1. 安裝
安裝方法比較簡單,直接使用pip3 install tensorflow命令進行安裝。如果要安裝指定版本,直接在后面指定版本即可:pip3 install tensorflow==2.2.0。
為了避免出錯,建議使用pip3 --default-timeout=60 install tensorflow -i https://pypi.douban.com/simple/進行安裝,來源見下面的問題…
注意:py3.8只能安裝 tf2以上的版本。
2. 遇到的問題
2.1 tf下載慢
tensorflow的安裝包比較大,可以使用國內的鏡像進行安裝。如,pip3 install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple,
2.2 使用清華源安裝tf報錯 OpenSSL.SSL.WantReadError
使用pip3 install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple命令安裝tf,下載一部分之后報錯:
ERROR: Exception: Traceback (most recent call last):File "/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl/urllib3/contrib/pyopenssl.py", line 313, in recv_intoreturn self.connection.recv_into(*args, **kwargs)File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1840, in recv_intoself._raise_ssl_error(self._ssl, result)File "/usr/lib/python3/dist-packages/OpenSSL/SSL.py", line 1646, in _raise_ssl_errorraise WantReadError() OpenSSL.SSL.WantReadError后面更換為,豆瓣源進行下載安裝(pip3 install tensorflow -i https://pypi.douban.com/simple/),下載中,最后一秒鐘被kill,安裝失敗,問題解決方法見 2.3
2.3 使用豆瓣源,在最后幾秒鐘程序被kill
使用命令pip3 install tensorflow -i https://pypi.tuna.tsinghua.edu.cn/simple安裝,在還剩1s時,出現killed字樣,如下所示
看了下pip man手冊,發現有–timeout參數,默認為15s,再次安裝,在出現eta 0:00:01時開始計時,15s后,被kill。所以這里kill是因為超時了,修改默認超時參數,問題終于解決。
這里修改方法為:pip3 --default-timeout=60 install tensorflow -i https://pypi.douban.com/simple/
安裝成功:
2.4 使用tf離線安裝包安裝 – 不推薦
自己下載安裝包,進行離線安裝,離線安裝命令為:
pip3 install tensorflow --no-index --find-links ./tensorflow-2.2.0-cp38-cp38-manylinux2010_x86_64.whl因為tf會依賴其他庫,如果采用離線安裝,遇到沒有的庫,需要自己一個個進行單獨安裝,比較麻煩,可以見下面的相關錯誤,在此不推薦離線安裝。(此處僅僅為了說明pip如何進行離線安裝)
安裝TensorFlow,遇到如下錯誤:
ERROR: Could not find a version that satisfies the requirement gast==0.3.3 (from tensorflow) (from versions: none)
ERROR: No matching distribution found for gast==0.3.3 (from tensorflow)
這里是,使用pip3 install gast==0.3.3 -i https://pypi.tuna.tsinghua.edu.cn/simple命令安裝gast。
ERROR: Could not find a version that satisfies the requirement tensorboard<2.3.0,>=2.2.0 (from tensorflow) (from versions: none)
ERROR: No matching distribution found for tensorboard<2.3.0,>=2.2.0 (from tensorflow)
ERROR: Could not find a version that satisfies the requirement wrapt>=1.11.1 (from tensorflow) (from versions: none)
ERROR: No matching distribution found for wrapt>=1.11.1 (from tensorflow)
3. 其他
對上面用到的幾種方法進行總結
3.1 離線安裝方法
pip3 install tensorflow --no-index --find-links ./tensorflow-2.2.0-cp38-cp38-manylinux2010_x86_64.whl3.2 超時時間參數設置
單次下載的超時參數修改,對應命令為:
pip3 --default-timeout=60 install ...3.3
總結
以上是生活随笔為你收集整理的使用pip安装TensorFlow 相关问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: BI 与 KPI/BSC
- 下一篇: 无线定位技术性能对照