在 Anaconda 中使用 virtualenv pip 安装 tensorflow
Installing tensorflow with virtualenv pip in Anaconda
我正在为 Windows 10 在 Anaconda 的 virtualenv 中尝试使用 pip 安装 tensorflow。激活我的 virtualenv 后,当我 运行 pip install tensorflow
时,我得到一个错误:
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
我正在使用。 post 的更新表明它现在应该可以工作,但它不适合我。我尝试了答案的建议,但运气并不好。
所以,我尝试了以下降级到 Python3.7:
- setting a virtualenv with Python3.7 version
- 正在安装包含 Python3.7
的 older version of Anaconda
但是当我激活 virtualenv 时,这些尝试中的任何一个都令人难以置信地看到 Python 切换回版本 3.8。即使我破坏环境并在较旧的 Anaconda 中重新创建它。
我还在 Anaconda 中使用 Python3.7 尝试了 (当使用更新的 Anaconda 时,它没有找到 Python 的正确版本)。它导致错误:
Cannot uninstall 'wrapt'. It is a distutils installed project and thus
we cannot accurately determine which files belong to it which would
lead to only a partial uninstall.
我修复了它 运行ning 并再次启动了 tensorflow 安装命令。安装和删除多个包后,显示以下错误:
ERROR: After October 2020 you may experience errors when installing or
updating packages. This is because pip will change the way that it
resolves dependency conflicts.
We recommend you use --use-feature=2020-resolver to test your packages
with the new resolver before it becomes the default.
pytest-doctestplus 0.2.0 requires pytest>=2.8.0, but you'll have
pytest 0.0.0 which is incompatible. pytest-astropy 0.5.0 requires
pytest>=3.1.0, but you'll have pytest 0.0.0 which is incompatible.
实际上,我可以看到安装没有成功:
pip freeze > requirements.txt
创建一个空 requirements.txt
在 Python 控制台中,当我尝试 import keras
时,它解析为:
Traceback (most recent call last):
File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 3, in <module>
from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
ModuleNotFoundError: No module named 'tensorflow'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 5, in <module>
raise ImportError(
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
看来无论我尝试多少路径,tensorflow都不喜欢Anaconda中的virtualenv。有人会有可行的方法吗?
我一直在使用带有 tensorflow 的虚拟环境,它运行良好。首先使用Anaconda创建一个新的环境。从 Anaconda 主页单击环境。
当“环境”页面出现时,单击“创建”。将弹出一个新的 window。为环境命名(例如将其命名为 tf),选中 python 复选框。从下拉列表 select python 3.7。安装了 python 3.7 后创建了一个名为 tf 的新环境。
现在转到 conda 的 Anaconda 提示符。输入 conda activate tf.现在使用 conda 安装 tensorflow(不要使用 pip)。 Conda 会自动安装 cudnn 7.6.5 和 CUDA Toolkit 10.1.243 以及 tensorflow 2.1.0。如果您想要 tensorflow 2.2,请先按照说明安装 2.1.0。然后用pip安装2.2,pip install tensorflow ==2.2.0。 2.2兼容2.1安装的工具包和cudnn版本。 Conda 最多只能安装 2.1.0 版本的 tensorflow。使用 pip 或 conda 安装您需要的任何其他软件包。
我正在为 Windows 10 在 Anaconda 的 virtualenv 中尝试使用 pip 安装 tensorflow。激活我的 virtualenv 后,当我 运行 pip install tensorflow
时,我得到一个错误:
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
所以,我尝试了以下降级到 Python3.7:
- setting a virtualenv with Python3.7 version
- 正在安装包含 Python3.7 的 older version of Anaconda
但是当我激活 virtualenv 时,这些尝试中的任何一个都令人难以置信地看到 Python 切换回版本 3.8。即使我破坏环境并在较旧的 Anaconda 中重新创建它。
我还在 Anaconda 中使用 Python3.7 尝试了
Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
我修复了它 运行ning
ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.
We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.
pytest-doctestplus 0.2.0 requires pytest>=2.8.0, but you'll have pytest 0.0.0 which is incompatible. pytest-astropy 0.5.0 requires pytest>=3.1.0, but you'll have pytest 0.0.0 which is incompatible.
实际上,我可以看到安装没有成功:
pip freeze > requirements.txt
创建一个空 requirements.txt在 Python 控制台中,当我尝试
import keras
时,它解析为:Traceback (most recent call last): File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 3, in <module> from tensorflow.keras.layers.experimental.preprocessing import RandomRotation ModuleNotFoundError: No module named 'tensorflow' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 5, in <module> raise ImportError( ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
看来无论我尝试多少路径,tensorflow都不喜欢Anaconda中的virtualenv。有人会有可行的方法吗?
我一直在使用带有 tensorflow 的虚拟环境,它运行良好。首先使用Anaconda创建一个新的环境。从 Anaconda 主页单击环境。 当“环境”页面出现时,单击“创建”。将弹出一个新的 window。为环境命名(例如将其命名为 tf),选中 python 复选框。从下拉列表 select python 3.7。安装了 python 3.7 后创建了一个名为 tf 的新环境。 现在转到 conda 的 Anaconda 提示符。输入 conda activate tf.现在使用 conda 安装 tensorflow(不要使用 pip)。 Conda 会自动安装 cudnn 7.6.5 和 CUDA Toolkit 10.1.243 以及 tensorflow 2.1.0。如果您想要 tensorflow 2.2,请先按照说明安装 2.1.0。然后用pip安装2.2,pip install tensorflow ==2.2.0。 2.2兼容2.1安装的工具包和cudnn版本。 Conda 最多只能安装 2.1.0 版本的 tensorflow。使用 pip 或 conda 安装您需要的任何其他软件包。