![](/img/trans.png)
[英]How do I set a different Python version in my environment from my base environment?
[英]Why is the tensorflow version I use in my notebook different from the version I use in my environment?
我在我的环境中安装了 tensorflow for linux 的 windows 子系统,但我不能在我的笔记本中使用它。 确实,这是我的版本:
(seg_env) antoi@LAPTOP-UTL8OHHO:/mnt/c/Users/antoi/Documents/Programming/Covent Garden/Segmentation$ pip list | grep tensorflow
tensorflow 2.1.0
tensorflow-estimator 2.1.0
tensorflow-text 2.1.1
但是当我尝试导入它时,我有:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-61-e25dcad80c44> in <module>
1 # import tensorflow.compat.v2 as tf
2 # !{sys.executable} -m pip install -q tensorflow-text
----> 3 from tensorflow_text import SentencepieceTokenizer
4
5 get_ipython().system("{sys.executable} -c 'import tensorflow as tf; print(tf.__version__)'")
ModuleNotFoundError: No module named 'tensorflow_text'
所以我尝试从笔记本安装它,它告诉我我的 tensorflow 版本不是它需要的版本:
Could not find a version that satisfies the requirement tensorflow<2.2,>=2.1.0 (from tensorflow-text) (from versions: 0.12.1, 1.0.0, 1.0.1, 1.1.0rc0, 1.1.0rc1, 1.1.0rc2, 1.1.0, 1.2.0rc0, 1.2.0rc1, 1.2.0rc2, 1.2.0, 1.2.1, 1.3.0rc0, 1.3.0rc1, 1.3.0rc2, 1.3.0, 1.4.0rc0, 1.4.0rc1, 1.4.0, 1.4.1, 1.5.0rc0, 1.5.0rc1, 1.5.0, 1.5.1, 1.6.0rc0, 1.6.0rc1, 1.6.0, 1.7.0rc0, 1.7.0rc1, 1.7.0, 1.7.1, 1.8.0rc0, 1.8.0rc1, 1.8.0, 1.9.0rc0, 1.9.0rc1, 1.9.0rc2, 1.9.0, 1.10.0rc0, 1.10.0rc1, 1.10.0, 1.10.1, 1.11.0rc0, 1.11.0rc1, 1.11.0rc2, 1.11.0, 1.12.0rc0, 1.12.0rc1, 1.12.0rc2, 1.12.0, 1.12.2, 1.12.3, 1.13.0rc0, 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 2.0.0a0, 2.0.0b0, 2.0.0b1)
No matching distribution found for tensorflow<2.2,>=2.1.0 (from tensorflow-text)
很奇怪不是吗? 我以为我有 tensorflow 2.1.0 ! 所以我尝试导入 tensorflow2:
import tensorflow.compat.v2 as tf
!{sys.executable} -c 'import tensorflow.compat.v2 as tf; print(tf.__version__)'
/home/antoi/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:516: 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/antoi/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:517: 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/antoi/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:518: 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/antoi/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:519: 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/antoi/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:520: 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)])
/home/antoi/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: 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_resource = np.dtype([("resource", np.ubyte, 1)])
/home/antoi/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: 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/antoi/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: 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/antoi/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: 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/antoi/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: 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/antoi/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: 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)])
/home/antoi/.local/lib/python3.6/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: 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_resource = np.dtype([("resource", np.ubyte, 1)])
1.14.0
看来我有 tensorflow 1.14.0 ! 那么为什么我在笔记本中使用的 tensorflow 版本与我在我的环境中使用的版本不同呢?
jupyter-notebook
时,它不是 anaconda 的的确:
(seg_env3) antoi@LAPTOP-UTL8OHHO:/mnt/c/Users/antoi/Documents/Programming/Covent Garden/Segmentation$ which jupyter
/home/antoi/.local/bin/jupyter
(seg_env3) antoi@LAPTOP-UTL8OHHO:/mnt/c/Users/antoi/Documents/Programming/Covent Garden/Segmentation$ which jupyter-notebook
/home/antoi/.local/bin/jupyter-notebook
我现在确定我没有使用 anaconda 的 jupyter notebook。 那么我如何启动 jupyter 的呢?
刚刚得到了解决方案,不知道是否与您的情况有关。 notebook 的问题在于它可能正在加载python默认版本的笔记本。 我刚刚遇到了一个类似的问题,我的笔记本中加载了 tensorflow 2.0 而不是 tf 1.1.4。 为此,我没有使用所需的 tf 版本创建一个新环境,并从该环境本地安装 jupyter。 从该环境再次启动 jupyter 时,它运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.