Python Forum

Full Version: sys.path for virtual environment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In a previous post I inquired about how to activate and use a virtual environment once the virtual environment is created
in the Jupyter notebook.

I can now get and use the virtual environment even in the jupyter notebook IDE. However when I try to import something
as basic as numpy it says numpy module not found.

Yet, I installed numpy and a simply pip list or conda list will confirm that.

Again, I am talking only the virtual environment, not the basic environment.

The response when I type

python -V in the virtual environment is

Python 3.611

That is exactly what I want.

But, when I type

import sys
print(sys.path)

I get the sys.path for the basic environment, not the virtual. There is a different version of python etc. That explains why it cannot find numpy in my virtual environment. It is looking in the wrong place.

How do I get the virtual environment system path? Maybe a better question is can I get and use the VE sys.path? If I can how do I do it?

Any help appreciated. thanks in advance.


Respectfully,

ErnestTBass
How did you add your virtual environment to the notebook kernel?

After doing that, you should have the option of starting a new notebook with either the global environment (probably called Python3) or your virtual environment. Do you have that option? Just trying to figure you how you know you're in the right environment.

---
Ah, I'm not using Anaconda. I think that it auto-adds the new environment to the notebook, so the step I thought you needed is probably already done.
I know that I am in the right environment because a pip or conda list sows the modules or libraries that I installed for this project. The modules and the python version are not the same as in the basic environment.

They are different which is why I created the virtual environment in the first place.

A simple command like:

python -V

will reveal which environment I am in. I installed numpy in my VE, and it installed fine. However, the python interpreter can not find numpy when i run my program in the VE because it is not in the sys.path.

I do not know if each VE has its own sys.path or if there is one global sys.path and that is it.

Any help appreciated. thanks in advance.

Respectfully,

ErnestTBass