Python Forum

Full Version: The command python3 -m venv venv does not correctly set sys.path
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am running POP_OS 22.04 and Python 3.10.6
If I run the following commands:
Output:
cd mkdir testenv cd testenv python3 -m venv venv source venv/bin/activate pip install django django-admin startproject website . python manage.py runserver
I get the error:
Error:
Traceback (most recent call last): File "/home/fred/testenv/manage.py", line 11, in main from django.core.management import execute_from_command_line ModuleNotFoundError: No module named 'django' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/fred/testenv/manage.py", line 22, in <module> main() File "/home/fred/testenv/manage.py", line 13, in main raise ImportError( ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
If I run python -m site I get:
sys.path = [
    '/home/fred/testenv',
    '/usr/lib/python310.zip',
    '/usr/lib/python3.10',
    '/usr/lib/python3.10/lib-dynload',
    '/usr/local/lib/python3.10/dist-packages',
    '/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/fred/.local' (exists)
USER_SITE: '/home/fred/.local/lib/python3.10/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
The site-packages directory '/home/fred/testenv/venv/lib/python3.10/site-packages' is not in the sys,path.

The same commands run perfectly fine on a virtual machine running the same OS. On the virtual machine the site-packages directory is in the sys.path.

I can get the my workstation's virtual environment to work if I do export the PYTHONPATH variable:
Output:
cd mkdir testenv cd testenv export PYTHONPATH='home/fred/testenv/venv/lib/python3.10/site-packages' python3 -m venv venv source venv/bin/activate pip install django django-admin startproject website . python manage.py runserver
Does anyone have any ideas as to why the python3 -m venv venv command does not set the sys.path correctly for the virtual environment on my workstation?
The reason the python -m venv command was not working was that in my .bash_aliases I had aliased python to be python="/usr/bin/python3" This was the problem. The explanation is found at the link below.
The link is a page on Jetbrains: FIx for path problem
(Feb-17-2023, 04:05 AM)echeadle Wrote: [ -> ]The reason the python -m venv command was not working was that in my .bash_aliases I had aliased python to be python="/usr/bin/python3" This was the problem. The explanation is found at the link below.
The link is a page on Jetbrains: FIx for path problem fnaf games
Thanks for this link.