EDIT:
- In addition to the behaviour outlined below, the Python3.10 based environment seems to be ignoring packages installed with the
pip -eoption (development mode). - Specifically, a package installed in development mode is not listed in
pip freeze(which, it does in the Python3.9 based virtual environment) and a simpleimport <package_name>fails. If the package is installed normally (i.e. not in development mode) everything works as expected.
I am using virtualenv to create a virtual environment based around Python 3.10. While virtualenv finishes without errors and does seem to activate, it still fails to pick up its own Python unless the PYTHONPATH environment variable has been set manually.
I am not sure if the situation I am faced with is due to Ubuntu's way of incorporating Python or the way virtualenv is setting up the environment so that it picks up a local interpreter. Here is what I have gathered this far:
My base system is an Ubuntu 21.04. It has its own Python 3 (Python3.9.5) installation which I have not touched at all except installing the
python3-virtualenvpackage usingapt.With Python 3.10, I installed the
python3.10-devpackage and proceeded to create a virtual environment in the usual way:> virtualenv -p python3.10 the_env/> source the_env/bin/activate
Although this looks OK so far, this environment does not have any information about its own
site-packagesdirectory. Not even the one thatvirtualenvis supposed to be creating which includespip. In this installation, if you try to> pip --versionyou simply get an error that thepippackage does not exist (thepip"executable" location is picked up correctly, but because the interpreter does not know anything about itssite-packagesit fails to start pip properly).
Long story short, I created two environments, one based on Python3.9 (which works perfectly) and one based on Python3.10 (which does not work) and did a very simple test in each environment:
> python -m site- On the Python3.9 environment,
sys.pathincludes a path that leads all the way to this particular environment'ssite-packages - On the Python3.10 environment,
sys.pathdoes not include that particular path but still includes the typical paths you expect to find (e.g. those pointing to the interpreter itself and the top environment directory but not the specific path that points to thesite-packageslocation.
- On the Python3.9 environment,
Following this, I defined a PYTHONPATH manually, before activating the environment which points exactly to the site-packages for that particular environment and everything worked as expected.
I suspect that this might be something to do with the fact that my system's Python is 3.9 which means that the USER_SITE variable is valid while in the case of Python3.10, it is not (because, I do not have a use for it, this is just a virtual environment I am creating). So, I suspect that this might be throwing off the way the site module determines where things are.
As I am not sure, I would like to ask the following:
Could this be something to do with the way Ubuntu handles the Python installation that might just be creating this small problem with virtual environments?
Could the problem be with
virtualenvthat does not explicitly specify aPYTHONPATH?Could this behaviour be something of a corner case of the
sitemodule?