I am running POP_OS 22.04 and Python 3.10.6
If I run the following commands:
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:
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: TrueThe 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?
Larz60+ write Jul-25-2023, 01:39 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.