无法使用带有 python 3.8 的 conda 安装 tensorflow
Unable to install tensorflow using conda with python 3.8
最近,我升级到使用python 3.8 的Anaconda3 2020.07。 anaconda 以前的版本,tensorflow 安装成功。 Tensorflow在此版本安装失败
我运行下面的命令;
conda install tensorflow-gpu
我收到的错误信息如下所示;
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- tensorflow-gpu -> python[version='3.5.*|3.6.*|3.7.*|>=3.7,<3.8.0a0|>=3.6,<3.7.0a0|>=3.5,<3.6.0a0|>=2.7,<2.8.0a0']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
The following specifications were found to be incompatible with your CUDA driver:
- feature:/win-64::__cuda==11.0=0
Your installed CUDA driver is: 11.0
是否有参数正确的conda命令可以成功安装tensorflow?
更新:
TF 现在兼容 Python 3.8
Tensorflow 与 Python 3.8 不兼容。参见 https://www.tensorflow.org/install/pip
您需要降级 python 版本:
conda install python=3.7
其实你可以直接在anaconda prompt里面使用pip,经过我的测试,发现conda是支持pypi的,首先运行管理员权限的anaconda prompt(in windows),然后输入“conda update --all”确保所有包都是最新的,最后输入“pip install tensorflow”进行安装(新版tensorflow已经包含tensorflow-gpu)
然后用VS code打开一个ipynb然后运行
import tensorflow as tf
tf.test.gpu_device_name()
一切看起来都不错。
更多信息请参考Anaconda官方文档:https://docs.anaconda.com/anaconda/ .
Python 3.8 support requires TensorFlow 2.2 or later.
所以有一个与python 3.8兼容的Tensorflow版本。
问题是TensorFlow 2.2.0 is not available through conda on Windows,这应该是你在运行
时得到PackagesNotFoundError
的原因
conda install tensorflow=2.2
编辑 21 年 3 月 15 日
使用 python 3.7 创建环境,然后激活它:
conda create -n p37env python=3.7
conda activate p37env
并安装tensorflow。
这对我有用,并从 Anaconda 用户指南中找到了答案(在如何使用不同的 python 版本:https://conda.io/projects/conda/en/latest/user-guide/getting-started.html#managing-python )
扩展 here with more explicit instructions and caveats. Pip is the recommended way to install latest version of tensorflow as per tensorflow's installation instructions——“虽然推荐使用 TensorFlow 提供的 pip 包,但也可以使用社区支持的 Anaconda 包。”
以下是在Conda环境下使用pip进行安装的代码:
conda create -n env_name python=3.8
conda activate env_name
conda install pandas scikit-learn matplotlib notebook ##installing usual Data Science packages that does include numpy and scipy
pip install tensorflow
python -c "import tensorflow as tf;print(tf.__version__)" ##checks tf version
一般来说,我们应该 be careful 同时混合使用两个包管理器(conda 和 pip)。所以,建议:
Only after conda has been used to install as many packages as possible
should pip be used to install any remaining software. If modifications
are needed to the environment, it is best to create a new environment
rather than running conda after pip.
举个例子,如果我们想在刚刚创建的env_name
环境中安装seaborn,我们应该:
conda create --name cloned_env --clone env_name
conda activate cloned_env
conda install seaborn
一旦我们检查 cloned_env
环境工作正常,我们就可以删除 env_name
环境。
在 anaconda 上安装 tensorflow 的最新进展。
https://anaconda.org/anaconda/tensorflow
https://anaconda.org/anaconda/tensorflow-gpu
9天前,Anaconda上传了一个新的tensorflow v2.3包。 Anaconda3 2020.07(使用python v3.8)用户可以通过以下命令轻松升级到tensorflow v2.3;
conda install -c anaconda tensorflow
conda install -c anaconda tensorflow-gpu
亲测安装成功。
此问题的其他答案现已过时。
对于 macos 用户,我建议使用 python 3.7 创建一个环境并在那里安装 tensorflow。
您也可以运行这些命令:
conda create -n new_env_name python=3.7
conda activate new_env_name
我 运行 在 Python 3.8.5 的 conda 提示符中遇到了同样的问题,并改用 Python 轮修复了它。以下是步骤:
- 打开 conda 提示符并安装 pip(如果您还没有):python -m pip install --upgrade pip
- python -m pip install --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.4.0-cp38-cp38-win_amd64.whl
注意:如果您需要 CPU 特定的张量流,请使用此轮:https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.4.0-cp38-cp38-win_amd64.whl
我在 Anaconda Spyder 中遇到了类似的问题。这是我的解决方案(在 Anaconda 控制台中):
conda install pip
pip install tensorflow ==2.2.0
我只是将 python 降级到 3.7,因为 tf 不适用于 3.8 版本,我也不能将 virtualenv 用于代码,这就是为什么
我想我们有两个选择
pip install tensorflow
或者我们可以使用另一个 anaconda 环境,如下所示
conda create -n tf tensorflow pydotplus jupyter
conda activate tf
对我来说唯一有效的答案是:
conda install -c conda-forge tensorflow
看来 GPU 上的 tensorflow 2.5 与 spyder 有问题。因此,我按照 anaconda 的建议创建了新环境并安装了 tensorflow gpu。现在我必须使用 prompt 或 jupyter 。至少它有效
最近,我升级到使用python 3.8 的Anaconda3 2020.07。 anaconda 以前的版本,tensorflow 安装成功。 Tensorflow在此版本安装失败
我运行下面的命令;
conda install tensorflow-gpu
我收到的错误信息如下所示;
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- tensorflow-gpu -> python[version='3.5.*|3.6.*|3.7.*|>=3.7,<3.8.0a0|>=3.6,<3.7.0a0|>=3.5,<3.6.0a0|>=2.7,<2.8.0a0']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
The following specifications were found to be incompatible with your CUDA driver:
- feature:/win-64::__cuda==11.0=0
Your installed CUDA driver is: 11.0
是否有参数正确的conda命令可以成功安装tensorflow?
更新:
TF 现在兼容 Python 3.8
Tensorflow 与 Python 3.8 不兼容。参见 https://www.tensorflow.org/install/pip
您需要降级 python 版本:
conda install python=3.7
其实你可以直接在anaconda prompt里面使用pip,经过我的测试,发现conda是支持pypi的,首先运行管理员权限的anaconda prompt(in windows),然后输入“conda update --all”确保所有包都是最新的,最后输入“pip install tensorflow”进行安装(新版tensorflow已经包含tensorflow-gpu)
然后用VS code打开一个ipynb然后运行
import tensorflow as tf
tf.test.gpu_device_name()
一切看起来都不错。
更多信息请参考Anaconda官方文档:https://docs.anaconda.com/anaconda/ .
Python 3.8 support requires TensorFlow 2.2 or later.
所以有一个与python 3.8兼容的Tensorflow版本。
问题是TensorFlow 2.2.0 is not available through conda on Windows,这应该是你在运行
时得到PackagesNotFoundError
的原因
conda install tensorflow=2.2
编辑 21 年 3 月 15 日
使用 python 3.7 创建环境,然后激活它:
conda create -n p37env python=3.7
conda activate p37env
并安装tensorflow。 这对我有用,并从 Anaconda 用户指南中找到了答案(在如何使用不同的 python 版本:https://conda.io/projects/conda/en/latest/user-guide/getting-started.html#managing-python )
扩展
以下是在Conda环境下使用pip进行安装的代码:
conda create -n env_name python=3.8
conda activate env_name
conda install pandas scikit-learn matplotlib notebook ##installing usual Data Science packages that does include numpy and scipy
pip install tensorflow
python -c "import tensorflow as tf;print(tf.__version__)" ##checks tf version
一般来说,我们应该 be careful 同时混合使用两个包管理器(conda 和 pip)。所以,建议:
Only after conda has been used to install as many packages as possible should pip be used to install any remaining software. If modifications are needed to the environment, it is best to create a new environment rather than running conda after pip.
举个例子,如果我们想在刚刚创建的env_name
环境中安装seaborn,我们应该:
conda create --name cloned_env --clone env_name
conda activate cloned_env
conda install seaborn
一旦我们检查 cloned_env
环境工作正常,我们就可以删除 env_name
环境。
在 anaconda 上安装 tensorflow 的最新进展。
https://anaconda.org/anaconda/tensorflow https://anaconda.org/anaconda/tensorflow-gpu
9天前,Anaconda上传了一个新的tensorflow v2.3包。 Anaconda3 2020.07(使用python v3.8)用户可以通过以下命令轻松升级到tensorflow v2.3;
conda install -c anaconda tensorflow
conda install -c anaconda tensorflow-gpu
亲测安装成功。
此问题的其他答案现已过时。
对于 macos 用户,我建议使用 python 3.7 创建一个环境并在那里安装 tensorflow。
您也可以运行这些命令:
conda create -n new_env_name python=3.7
conda activate new_env_name
我 运行 在 Python 3.8.5 的 conda 提示符中遇到了同样的问题,并改用 Python 轮修复了它。以下是步骤:
- 打开 conda 提示符并安装 pip(如果您还没有):python -m pip install --upgrade pip
- python -m pip install --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-2.4.0-cp38-cp38-win_amd64.whl
注意:如果您需要 CPU 特定的张量流,请使用此轮:https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow_cpu-2.4.0-cp38-cp38-win_amd64.whl
我在 Anaconda Spyder 中遇到了类似的问题。这是我的解决方案(在 Anaconda 控制台中):
conda install pip
pip install tensorflow ==2.2.0
我只是将 python 降级到 3.7,因为 tf 不适用于 3.8 版本,我也不能将 virtualenv 用于代码,这就是为什么
我想我们有两个选择
pip install tensorflow
或者我们可以使用另一个 anaconda 环境,如下所示
conda create -n tf tensorflow pydotplus jupyter
conda activate tf
对我来说唯一有效的答案是:
conda install -c conda-forge tensorflow
看来 GPU 上的 tensorflow 2.5 与 spyder 有问题。因此,我按照 anaconda 的建议创建了新环境并安装了 tensorflow gpu。现在我必须使用 prompt 或 jupyter 。至少它有效