gosiia
gosiia

Reputation: 169

What is the purpose of pyvenv.cfg after the creation of a Python virtual environment?

When I create a virtual environment in Python on Windows cmd, in the virtual environment folder, the following files appear:

What is the goal of pyvenv.cfg creation? Can I use it in any way?

Upvotes: 11

Views: 25907

Answers (3)

Carlos Man
Carlos Man

Reputation: 368

Another use case, apart from the obvious ones already mentioned, is that if you use the "command" configuration option, you can actually get Visual Studio Code to start your development environment terminal with the virtual environment already activated, as in this example (Homebrew and macOS specific):

home = /opt/homebrew/opt/[email protected]/bin
include-system-site-packages = false
version = 3.11.3
executable = /opt/homebrew/Cellar/[email protected]/3.11.3/Frameworks/Python.framework/Versions/3.11/bin/python3.11
command = /opt/homebrew/opt/[email protected]/bin/python3.11 -m venv /Users/<your-username>/<your-project-folder>

Upvotes: 2

Noah Clements
Noah Clements

Reputation: 31

One of the problems though is that the "version=" information lies. For example, in a recent .venv I created for a project it says:

home = /Library/Frameworks/Python.framework/Versions/3.10/bin
include-system-site-packages = false
version = 3.10.4

however, when I just installed python 3.10.6, it updates the base 3.10, and now the version info is incorrect. As I am just doing tutorials, I am happy that the environment now has the latest version, but I don't see the point of having incorrect version information in the cfg file.

In looking at the venv/bin folder I see symlinks of python, python3, and python3.10 commands.

It appears that by default on my system the venv is using symlinks instead of copies of the python binaries, which is fine, but if using symlinks, the cfg should not list the subversion number. We can specify that the venv command create copies instead, but my problem is with the incorrect info on the .cfg file.

Upvotes: 3

Umar Hayat
Umar Hayat

Reputation: 4991

pyvenv.cfg is a configuration file that stores information about the virtual environment such as

  • standard libraries path
  • Python version
  • interpreter version
  • virtual env flags
  • or any other venv configs

If print content of pyvenv.cfg

$ cat myenv/pyvenv.cfg
home = /usr/bin
include-system-site-packages = false
version = 3.8.5

This is a sample output of the pyvenv.cfg file.

Cheers!

Upvotes: 5

Related Questions