Python Forum
sys.path for virtual environment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sys.path for virtual environment
#1
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
Reply
#2
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.
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with creating folder and "virtual environment" AudunNilsen 1 171 Mar-21-2024, 04:41 AM
Last Post: deanhystad
  Installing python packages in a virtual environment Led_Zeppelin 1 710 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Problem with virtual environment standenman 2 942 Feb-23-2023, 07:09 PM
Last Post: standenman
Question Virtual Environment (using VS Code) Ashcora 4 12,466 Feb-15-2023, 07:17 PM
Last Post: snippsat
  How do I link the virtual environment of that project to the 3.9.2 version of python? Bryant11 1 1,331 Feb-26-2022, 11:15 AM
Last Post: Larz60+
  Project structure with a virtual environment gdbengo 1 1,388 Jan-26-2022, 03:22 PM
Last Post: snippsat
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,148 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Virtual environment path? Led_Zeppelin 1 2,260 Jul-22-2021, 01:40 PM
Last Post: snippsat
  virtual environment heye 4 2,396 Jul-04-2021, 06:47 AM
Last Post: ndc85430
  import statement in a virtual environment leodavinci1990 1 2,295 Mar-04-2021, 12:57 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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