Robert Townley
Robert Townley

Reputation: 3574

Discover path to python version used to make virtualenv

I have an old computer with dozens of old python projects installed, each with its own different virtualenv, and many of which built with different versions of python.

I'd prefer not to have to download these different versions when I create new virtualenvs via virtualenv -p whatever path that version of python has

My question is: within a virtualenv, is there a command I can run to find the path to the version of python which was used to create that particular environment?

For example, if I created a venv with 'virtualenv -p /usr/bin/python3.4' and then ran this command with the venv activated, it would return '/usr/bin/python3.4'

Upvotes: 0

Views: 165

Answers (2)

jmd_dk
jmd_dk

Reputation: 13120

You could try running something like this from the command line:

python -c "import sysconfig; print(sysconfig.get_config_var('BINDIR'))"

Upvotes: 0

Dean Fenster
Dean Fenster

Reputation: 2395

Since virtualenv copies python completely (including the binary) there is no way to know the exact path it originated from.

However, you can easily find the version by running ./python --version inside the environment's bin folder.

Upvotes: 1

Related Questions