简体   繁体   English

如何使用“venv”更新 Python 虚拟环境以使用更新版本的 Python?

[英]How do I update a Python virtual environment with `venv` to use a newer version of Python?

I have recently installed Python 3.8.0 alongside Python 3.7.4.我最近安装了 Python 3.8.0 和 Python 3.7.4。

I have some virtual environments (created using python -m venv <directory> that are based on v3.7.4. How do I update them to use v3.8.0?我有一些基于 v3.7.4 的虚拟环境(使用python -m venv <directory>创建。如何更新它们以使用 v3.8.0?

Do I need to create a new virtual environment and reinstall the dependencies, scripts, etc.?我是否需要创建一个新的虚拟环境并重新安装依赖项、脚本等?


Note: There are some existing Q&A's ( such as this ) that deal with the older virtualenv package/tool.注意:有一些现有的问答(例如 this )处理较旧的virtualenv包/工具。 I'm specifically asking about the new built-in venv module, which is a standard built-in to Python since v3.3 and has some differences from virtualenv .我特别询问新的内置venv模块,它是自 v3.3 以来 Python 的内置标准,与virtualenv有一些差异。

I guess what you're looking for is the --upgrade parameter.我猜你正在寻找的是--upgrade参数。

python -m venv --help
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
            [--upgrade] [--without-pip] [--prompt PROMPT]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system
                        site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks
                        are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when
                        symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it
                        already exists, before environment creation.
  --upgrade             Upgrade the environment directory to use this version
                        of Python, assuming Python has been upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual
                        environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this
                        environment.

You need to run it with the targeted python version, for example in this case:您需要使用目标 python 版本运行它,例如在这种情况下:

python3.8 -m venv --upgrade <path_to_dir>

Assuming that python3.8 is the name of your python 3.8.0 executable.假设 python3.8 是您的 python 3.8.0 可执行文件的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在虚拟环境中使用编辑器/IDE | 蟒蛇和venv? - How can I use editors/IDEs with a virtual environment | python and venv? 如何在虚拟环境中使用不同的 python3.x 版本的 python - How do I use a different python3.x version of python inside virtual environment 如何使用 python 脚本激活 python 虚拟环境 (VENV) - How to active python virtual environment (VENV) using python script 现在 python 2 已弃用,我们还需要使用 venv 来创建虚拟环境吗? - Now that python 2 is deprecated, do we still need to use the venv for creating virtual environment? 如何在标准库中的 venv 中使用不同的 Python 版本? (不是 virtualenv!) - How do I use different Python version in venv from standard library? (Not virtualenv!) 如何在虚拟环境中启动 python 并将软件包安装到正确路径中的 venv? - How do a start python in a virtual environment with the packages installed to the venv in the correct path? Python:如何在 pyenv-virtual-environment 中更新 python 版本? - Python: How can I update python version in pyenv-virtual-environment? Python 虚拟环境 (venv) 用户包 - Python virtual environment (venv) user packages 删除在 python3 中使用 venv 创建的虚拟环境 - remove virtual environment created with venv in python3 如何设置 python 虚拟环境? - How do I setup a python virtual environment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM