多个版本的Tensorflow导致问题

时间:2019-12-17 07:29:00

标签: python python-3.x tensorflow pip knowledge-graph

长话短说:我使用Amazon EC2实例,并试图使用名为Ampligraph的程序包,该程序包在内部使用TensorFlow(TF)。我使用此installation guide通过PIP安装了它。我运行了以下脚本,将模型加载到系统中。

from ampligraph.utils import restore_model
model = restore_model(model_name_path = model_path)

它给我`AttributeError:模块'tensorflow'没有属性'random'

我关注了this之类的StackOverFlow帖子,并且了解到我的TF版本有问题。

当我运行以下命令来检查TF版本时

python3 -c 'import tensorflow as tf; print(tf.__version__)'

这就是我得到的:

I tensorflow/stream_executor/dso_loader.cc:126] Couldn't open CUDA library libcudnn.so.5. LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64
I tensorflow/stream_executor/cuda/cuda_dnn.cc:3517] Unable to load cuDNN DSO
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
/home/ubuntu/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:455: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/ubuntu/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:456: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/ubuntu/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:457: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/ubuntu/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:458: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/ubuntu/.local/lib/python3.5/site-packages/tensorflow/python/framework/dtypes.py:459: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
1.0.1

所以,我知道TF的版本是1.0.1(最后一行)。

同样,我通过pip安装了TF:

sudo pip3 install tensorflow==1.13.1

已成功安装。但是,当我运行命令检查TF版本时,它显示与上面相同的消息,并且版本仍为1.0.1

我在做什么错了?

很抱歉,很长的帖子 谢谢!

1 个答案:

答案 0 :(得分:1)

首先,检查pip3是否与别名为python3的解释器匹配:运行

$ pip3 --version

并检查解释器版本为3.5。输出示例:

pip 19.3.1 from /usr/lib64/python3.5/site-packages/pip (python 3.5)

如果版本不匹配,则说明您安装了多个版本的Python,并且pip3安装了另一个Python版本的软件包。确定对于Python 3.5(例如pippip3.5),别名为python3.5 -m pip的命令是什么,并使用正确的命令为Python 3.5重新安装tensorflow

第二,您可能同时为同一个解释器安装了两个版本的tensorflow-全局版本(通过sudo pip3 install tensorflow安装)和仅用户版本(通过pip3 install tensorflow --user安装),注意未使用sudo)。要检查,请运行:

$ pip3 list --user

,然后检查是否列出了tensorflow。如果是,请卸载仅用于用户的一个:

$ pip3 uninstall tensorflow --user

或升级它并卸载全局的:

$ pip3 install tensorflow --upgrade --user
$ sudo pip3 uninstall tensorflow -y
相关问题