a newer version of python_How do I update a Python virtual environment with `venv` to use a newer ve...

问题

I have recently installed Python 3.8.0 alongside Python 3.7.4.

I have some virtual environments (created using python -m venv that are based on v3.7.4. How do I update them to use 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. 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.

回答1:

I guess what you're looking for is the --upgrade parameter.

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:

python3.8 -m venv --upgrade

Assuming that python3.8 is the name of your python 3.8.0 executable.

来源:https://stackoverflow.com/questions/58562928/how-do-i-update-a-python-virtual-environment-with-venv-to-use-a-newer-version

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值