如何使用 `venv` 更新 Python 虚拟环境以使用更新版本的 Python?
How do I update a Python virtual environment with `venv` to use a newer version of Python?
我最近安装了 Python 3.8.0 和 Python 3.7.4。
我有一些基于 v3.7.4 的虚拟环境(使用 python -m venv <directory>
创建。如何更新它们以使用 v3.8.0?
我是否需要创建一个新的虚拟环境并重新安装依赖项、脚本等?
注意:有一些现有的问答 (such as this) 涉及较旧的 virtualenv
package/tool。我特别询问新的内置 venv
模块,它是自 v3.3 以来 Python 的标准内置模块,与 virtualenv
.[=17= 有一些差异]
我猜你要找的是 --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.
您需要 运行 使用目标 python 版本,例如在这种情况下:
python3.8 -m venv --upgrade <path_to_dir>
假设 python3.8 是您的 python 3.8.0 可执行文件的名称。
我最近安装了 Python 3.8.0 和 Python 3.7.4。
我有一些基于 v3.7.4 的虚拟环境(使用 python -m venv <directory>
创建。如何更新它们以使用 v3.8.0?
我是否需要创建一个新的虚拟环境并重新安装依赖项、脚本等?
注意:有一些现有的问答 (such as this) 涉及较旧的 virtualenv
package/tool。我特别询问新的内置 venv
模块,它是自 v3.3 以来 Python 的标准内置模块,与 virtualenv
.[=17= 有一些差异]
我猜你要找的是 --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.
您需要 运行 使用目标 python 版本,例如在这种情况下:
python3.8 -m venv --upgrade <path_to_dir>
假设 python3.8 是您的 python 3.8.0 可执行文件的名称。