You are not logged in.

#1 2024-04-29 02:44:23

jronald
Member
Registered: 2022-05-09
Posts: 74

[SOLVED] python venv needs recreating after python upgrade

When python in system path is 3.11, a venv is created and it works well.
After python in system path upgraded to 3.12, python in venv failed to work.
Recreating venv solve the problem.
The new problem is that python in venv takes several GB for the libraries,
recreating is expensive, any cheap way?

Last edited by jronald (2024-04-29 04:38:07)

Offline

#2 2024-04-29 03:36:30

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 659

Re: [SOLVED] python venv needs recreating after python upgrade

I'll try to give an answer, but first what command did you use to create the venv originally?

Offline

#3 2024-04-29 03:51:27

jronald
Member
Registered: 2022-05-09
Posts: 74

Re: [SOLVED] python venv needs recreating after python upgrade

bulletmark wrote:

I'll try to give an answer, but first what command did you use to create the venv originally?

I used the vscodium python plugin (ms-python) to create venv.

Offline

#4 2024-04-29 04:32:05

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 659

Re: [SOLVED] python venv needs recreating after python upgrade

I don't normally use VS Code but I just had a look and it seems to use it's own custom implementation equivalent to `python -m venv` so if you want to keep using that then you have to delete the venv and recreate it via it's GUI. I don't actually think there is any other choice to rebuild venvs with a new base python other than delete + recreate but my suggestion is for people to migrate from `python -m venv` or `virtualenv` command line tools to the much better `uv` tool which is up to orders of magnitude faster than the older (venv + pip) tools and is a much better design. I anticipate VS Code (and other tools using venv and/or pip) will eventually migrate to uv also.

Offline

#5 2024-04-29 04:37:37

jronald
Member
Registered: 2022-05-09
Posts: 74

Re: [SOLVED] python venv needs recreating after python upgrade

bulletmark wrote:

I don't normally use VS Code but I just had a look and it seems to use it's own custom implementation equivalent to `python -m venv` so if you want to keep using that then you have to delete the venv and recreate it via it's GUI. I don't actually think there is any other choice to rebuild venvs with a new base python other than delete + recreate but my suggestion is for people to migrate from `python -m venv` or `virtualenv` command line tools to the much better `uv` tool which is up to orders of magnitude faster than the older (venv + pip) tools and is a much better design. I anticipate VS Code (and other tools using venv and/or pip) will eventually migrate to uv also.

Thanks, it's quite helpful, I'll try.

Offline

#6 2024-04-29 04:53:28

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 659

Re: [SOLVED] python venv needs recreating after python upgrade

BTW, you don't have to use that GUI within VS Code to create/maintain your venv. You can create it by hand in a terminal window, e.g. using uv venv + uv pip install, and then simply click on the Python button in the bottom right corner of VS Code and select that created venv/bin/python. VS Code will happily use that venv regardless of how it was created.

Offline

Board footer

Powered by FluxBB