虚拟环境下降级Python版本
关于TensorFlow,我总是遇到相同的错误: modulenotfounderror:no模块名为'tensorflow.contrib'
。
我实际上是在使用Python版本3.9
,但是,在线阅读,似乎版本3.7
是可以与TensorFlow版本一起使用的最后一个稳定> 2.0 。
不幸的是,我已经用错误的版本的Python启动了我的项目,我想降级它,我该怎么做?
I am always getting the same error regarding TensorFlow:ModuleNotFoundError: No module named 'tensorflow.contrib'
.
I am actually using Python version 3.9
but, reading online, it seems that version 3.7
is the last stable one that can work with TensorFlow version >2.0
.
Unfortunately I have started my project in a venv
with the wrong version of Python and I would like to downgrade it, how can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基于上面 @chepner 的评论,由于 venvs 只是目录,您可以保存当前状态并启动一个新的虚拟环境。
希望有帮助!
Building on @chepner's comment above, since venvs are just directories, you can save your current state and start a fresh virtual environment instead.
Hope that helps!
有
venv --upgrade
命令,但它主要用于在补丁版本之间进行更新(例如从 3.9.15 到 3.9.16)。您需要额外的步骤才能在不同的次要版本之间进行更新。让我引导您完成它。
假设您安装了两个版本的 Python:
并且您的环境是使用版本 3.9 创建的,并且位于
venv
子目录中:使用这些命令从 3.9 降级到 3.7:
结果如下:
There's the
venv --upgrade <ENV_DIR>
command, but it's mainly intended to update between patch versions (e.g. from 3.9.15 to 3.9.16).You'll need extra steps to update between different minor versions. Let me walk you through it.
Assuming you have both versions of Python installed:
And that your environment was created using version 3.9, and it's in a
venv
subdirectory:Use these commands to downgrade from 3.9 to 3.7:
Here's the result:
tf.contrib 已从最新版本的
TensorFlow 2.x
并替换为 TF Slim。建议使用升级版本的
TensorFlow
受益于TensorFlow
提供的最新特性和功能。但是,要降级 python
您需要卸载现有的
python
版本并重新安装所需的python
版本并设置环境.如果您使用的是
Anaconda
IDE,请使用以下命令:请查看此链接了解更多详细信息。
tf.contrib is deprecated from the latest version of
TensorFlow 2.x
and is replaced with TF Slim.It is recommended to use the upgraded version of
TensorFlow
to have the benefit of the latest features and functionalities provided byTensorFlow
.However, To downgrade python
You need to uninstall the existing
python
version and re-install the requiredpython
version and set up your environment.If you are using
Anaconda
IDE, then use the below command:Please check this link for more details.