Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual Environment calling global installation of Python instead of venv-specifc version

I'm having an issue where for some reason the virtual environments that I'm creating are accessing my system-wide installations of Python and pip when they shouldn't be.

Here's my fairly simple workflow just make sure I'm not missing anything obvious (Windows 10, Python 3.8.2):

python -m venv venv
venv\Scripts\activate.bat

My path is now prepended by (venv), as you'd expect. However,

pip list

lists all of the system-wide pip packages I have instead of just the ones that should be in that venv.

pyvenv.cfg indicates that

include-system-site-packages = false

When I open the interpreter using

python

In the virtual environment,

sys.executable    

Returns the path on my C drive and

print(pip.__file__)

Does the same. I suspect they should instead be pointing to the interpreter and pip in the virtual environment but don't know how to make that happen.

Edit: 4/27/20, Still dealing with this issue, I have tried:

  • uninstalling and reinstalling Python, both from python.org and the MS Store

  • Installing python in a new location

  • Clearing my user and system environment variables and then adding in just the ones for Python 3.8.

I'm really at a loss here, would appreciate any help.

like image 217
codydegen Avatar asked Oct 15 '25 04:10

codydegen


2 Answers

To anyone looking at this later on, I eventually realized that the problem was only occurring in a specific folder. Making virtual environments elsewhere on my computer seems to work fine. Why this is the case? I have no idea. I'm curious, but not enough to spend another second on this problem. So there you go.

like image 166
codydegen Avatar answered Oct 16 '25 16:10

codydegen


I had the same problem too. It might be that the path to your virtual environment has a character with accent in it. This basically means that you will have to alter the \Scripts\activate.bat file. In order to see if that's the case, use the following procedure:

  1. Activate the virtual environment by running the file \Scrips\activate.bat
  2. Run the following command:
echo %PATH%

There should appear a bunch of paths, being path\to\your\virtual\environment\Scripts the first of them (this is obligatory). Check if this path is exactly the same as it is supposed to be (meaning it should have no "strange" characters instead of characters with accents). If there are any discrepancies, I suggest you alter your \Scripts\activate.bat according to https://stackoverflow.com/a/22348546/11923771, reopen your Command Prompt and follow steps 1 and 2 again to see if your problem was solved.

like image 22
gabrielsilva Avatar answered Oct 16 '25 18:10

gabrielsilva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!