Att Righ
Att Righ

Reputation: 1799

How do I change the default version of python used by virtualenv?

virtualenv when running on my computer is not using the verison of python3 that I expect. I want it to use the same version as that returned by which python - is there a way of changing the default version of python that virtualenv uses.

I can use the -p flag in a particular invocation, but I can't find a way of changing the default in the man page.

There is an obvious terrible work around with bash aliases but this is terrible.

Upvotes: 0

Views: 105

Answers (1)

anthony sottile
anthony sottile

Reputation: 70233

virtualenv defaults to the python it was run with. I do this on my machine with ... more virtualenvs!

step 1: create a virtualenv at a ~well known location in your home directory. I use ~/opt/venv. make sure to use the python you want to be the default (in my case, python3.9)

virtualenv ~/opt/venv -p python3.9

step 2: install virtualenv into that virtualenv

~/opt/venv/bin/pip install virtualenv

step 3: put that virtualenv onto your PATH (for example, I have ~/bin on the path, you might have ~/.local/bin or some other directory

ln -s ~/opt/venv/bin/virtualenv ~/bin/

now when you make virtualenvs, it will use this executable and default to the python you picked

$ which virtualenv
/home/asottile/opt/venv/bin/virtualenv

Upvotes: 1

Related Questions