我目前安装了 Tensorflow 1.14.0。我将 Python 升级到 3.7,以便至少获得 Tensorflow 1.15(如果不是 2.0)。我的 python 更新成功:
pi@HCoreDEV:~ $ python --version
Python 3.7.0
pi@HCoreDEV:~ $ python3 --version
Python 3.7.0
现在,当我尝试
sudo pip install --upgrade tensorflow
我得到以下信息(还有很多行,但他们都说“要求已经满足”或“最新”):
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already up-to-date: tensorflow in /usr/local/lib/python3.5/dist-packages (1.14.0)
请注意,它默认为python 3.5文件夹.... ????
但是:如果我尝试检查 TF 的版本:
pi@HCoreDEV:~ $ python3 -c 'import tensorflow as tf; print(tf.__version__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
pi@HCoreDEV:~ $ python -c 'import tensorflow as tf; print(tf.__version__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
它甚至没有安装任何 TF。
这是我的更新替代输出:
pi@HCoreDEV:~ $ sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.7 3 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.5 2 manual mode
* 3 /usr/bin/python3.7 3 manual mode
Press <enter> to keep the current choice[*], or type selection number:
最后,这是我的来源 ~/.bashrc 文件中 python 和 python3 的别名,以供参考:
alias python='/usr/bin/python3.7'
alias python3='/usr/bin/python3.7'
那么为什么在确认 python3.7 安装并运行后,Tensorflow 只查看 3.5 文件夹,看到在我升级到 3.7 之前正在运行的现有安装,并说满足要求?
当我在终端窗口中输入“python”时,输出如下:
pi@HCoreDEV:~ $ python
Python 3.7.0 (default, Feb 6 2020, 16:11:11)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
最后,这是我的 sys.path 输出:
>>> import sys
>>> sys.path
['', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages']
>>>
需要一些帮助,我希望我已经提供了足够的信息,以便让比我更有经验的人清楚地看到这个问题。