3

In Ubuntu 16.04, when I do python3.6 -m venv myenvironment, venv does not install the python 3.6 binaries in ../myenvironment/bin but only symlinks to the system binaries. The official docs for 3.6 suggests otherwise:

28.3.1 . . . (venv) also creates a bin subdirectory containing a copy of the python binary.

Unless by "copy" they mean a symlink, venv is not doing what the doc says. The pip binaries are there, but not python 3.6 or any other version binaries.

Maybe it doesn't matter since within that environment 3.6 will be the version used. But then which modules/packages will it use? venv did create the lib/python3.6/site-packages subdirectory as expected. Should I assume that unless I put a different version of a module/package there that the system-wide library will be used within this virtual environment?

Edit: In partial answer to my own question, it seems the default on Ubuntu 16.04 is for venv to not install the python binaries. Adding the --copies option forces venv to place the binaries into the env's ../bin directory. venv creates a subdirectory for the env's site-packages as expected. It does not, however, put the standard library modules/packages into the env's ../lib/python3.6 sub-directory.

According to the output of print(sys.path) (when run from within the env), the env's python copy still looks in the system's /usr/lib/python3.6 directory for the standard library. I guess that's okay if that's how it should work, but does one ever want to use a particular version of a module or package in the standard library, or is that just not ever done and only none-standard-library modules/packages are placed in the env's site-packages subdirectory?

2nd Edit: Here's an SO Q&A on the venv's behavior regarding standard library modules and packages: Where is the standard library in python virtual environment? The gist of the answers is that venv does not create a copy of the standard library in the env's directories. The system-wide standard library is always used. At least one of the participants in that Q&A commented it was odd that venv behaves that way. Seems odd to me as well. Does anyone know why?

Todd Carney
  • 165
  • 13

0 Answers0