多个版本的 Tensorflow 导致问题
Multiple versions of Tensorflow causing issues
长话短说:我使用一个 Amazon EC2 实例并尝试使用这个名为 Ampligraph 的包,它在内部使用 TensorFlow(TF)。我使用这个 installation guide 通过 PIP 安装了它。我 运行 这些下面的脚本将模型加载到系统。
from ampligraph.utils import restore_model
model = restore_model(model_name_path = model_path)
它给我 `AttributeError: module 'tensorflow' has no attribute 'random'
我关注了多个 Whosebug post,例如 ,我知道我的 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
我做错了什么?
抱歉久了post
谢谢!
首先,检查 pip3
是否匹配别名为 python3
的解释器:运行
$ pip3 --version
并检查解释器版本是 3.5。示例输出:
pip 19.3.1 from /usr/lib64/python3.5/site-packages/pip <b>(python 3.5)</b>
如果版本不匹配,则说明您安装了 Python 的多个版本,并且 pip3
为另一个 Python 版本安装了软件包。确定 Python 3.5 的 pip
别名的命令(例如 pip3.5
或 python3.5 -m pip
)并使用正确的命令为 Python 3.5 重新安装 tensorflow
.
其次,您可以为同一个解释器同时安装两个版本的 tensorflow
- 全局版本(通过 sudo pip3 install tensorflow
安装)和用户专用版本(通过 [=23= 安装) ], 注意没有使用 sudo
)。要检查这一点,运行:
$ pip3 list --user
并检查是否列出了 tensorflow
。如果是,要么卸载用户专用的:
$ pip3 uninstall tensorflow --user
或升级并卸载全局的:
$ pip3 install tensorflow --upgrade --user
$ sudo pip3 uninstall tensorflow -y
长话短说:我使用一个 Amazon EC2 实例并尝试使用这个名为 Ampligraph 的包,它在内部使用 TensorFlow(TF)。我使用这个 installation guide 通过 PIP 安装了它。我 运行 这些下面的脚本将模型加载到系统。
from ampligraph.utils import restore_model
model = restore_model(model_name_path = model_path)
它给我 `AttributeError: module 'tensorflow' has no attribute 'random'
我关注了多个 Whosebug post,例如
当我运行下面的命令检查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
我做错了什么?
抱歉久了post 谢谢!
首先,检查 pip3
是否匹配别名为 python3
的解释器:运行
$ pip3 --version
并检查解释器版本是 3.5。示例输出:
pip 19.3.1 from /usr/lib64/python3.5/site-packages/pip <b>(python 3.5)</b>
如果版本不匹配,则说明您安装了 Python 的多个版本,并且 pip3
为另一个 Python 版本安装了软件包。确定 Python 3.5 的 pip
别名的命令(例如 pip3.5
或 python3.5 -m pip
)并使用正确的命令为 Python 3.5 重新安装 tensorflow
.
其次,您可以为同一个解释器同时安装两个版本的 tensorflow
- 全局版本(通过 sudo pip3 install tensorflow
安装)和用户专用版本(通过 [=23= 安装) ], 注意没有使用 sudo
)。要检查这一点,运行:
$ pip3 list --user
并检查是否列出了 tensorflow
。如果是,要么卸载用户专用的:
$ pip3 uninstall tensorflow --user
或升级并卸载全局的:
$ pip3 install tensorflow --upgrade --user
$ sudo pip3 uninstall tensorflow -y