gpt4 book ai didi

virtualenv - 如何更改已经存在的 virtualenv 的 python 版本?

转载 作者:行者123 更新时间:2023-12-03 11:24:12 86 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Can existing virtualenv be upgraded gracefully?

(5 个回答)


2年前关闭。




我已经使用 python 3.6 创建了一个虚拟环境,然后我进行了系统升级,并且在系统范围内安装了 python 3.7。现在我无法在那个虚拟环境中执行 python 文件,因为它正在搜索 python 3.6。

如何升级 virtualenv python 版本以匹配系统范围的版本或如何降级该特定虚拟环境的 python 版本?

我正在使用manjaro。

最佳答案

编辑 1

做了一些测试,发现了另一种更“优雅”的方式来(至少)更新可执行文件。让我们假设虚拟环境最初是这样创建的virtualenv -p /path/to/my/python2.7 .venv .可执行文件可以更新为特定的 python 版本,如下所示:virtualenv --clear -p /path/to/my/python3.6 .venv .请验证 python .venv/bin/python 中的符号链接(symbolic link)使用 ls -la .venv/bin/python 更新.旧的可执行文件仍将位于 ./venv/bin/ .

注意:您需要安装特定目标版本的python。

this link这很好地解释了它。

Virtualenvwrapper comes with some convenient commands for managing your virtualenvs.

To change your Python version:

  1. Deactivate your current environment session.

  2. If you have many packages or libraries installed, it would be a good idea to make a requirements.txt file. Remember to edit version as necessary.

  3. Remove the virtualenv with the wrapper command: rmvirtualenv

    • This will remove the virtualenv, but leave your project files.
  4. Make a new virtualenv with the Python version you want.

    • Example: mkvirtualenv -p python3 env-name

    • You can specify the Python version with the -p flag and version. If you have a requirements.txt file, you can specify that with -r requirements.txt

  5. Now bind your new virtualenv to your project directory. You can specify the full paths, but it is easier to have your new virtualenv activated and be in your project directory. Then, run the command:

Example: setvirtualenvproject



请让我/我们知道这个答案是否对您有帮助!

关于virtualenv - 如何更改已经存在的 virtualenv 的 python 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51915484/

86 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com