Python Forum
The command python3 -m venv venv does not correctly set sys.path
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The command python3 -m venv venv does not correctly set sys.path
#1
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?
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.
Reply
#2
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
Reply
#3
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Emacs 28 and venv pisterpesto 1 1,921 Nov-30-2022, 05:55 AM
Last Post: Larz60+
  paths for venv Skaperen 5 1,858 Jun-14-2022, 10:04 AM
Last Post: snippsat
  venv conflict at shell prompt Skaperen 3 2,874 Feb-21-2019, 02:18 AM
Last Post: Larz60+
  PyCharm virtual environment (venv) issues? j.crater 1 2,293 Aug-14-2018, 10:22 PM
Last Post: Larz60+
  os.path.join, bytearray, python2 vs python3 Skaperen 0 2,028 Jul-06-2018, 01:19 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020