Add your virtual environment as Python kernel in this way (Make sure it's activated):
(venv)
$ ipython kernel install --name "local-venv-kernel" --user
Now, you can select the created kernel "local-venv-kernel" when you start Jupyter notebook or lab.
You could check the installed libraries using this code in a notebook cell:
!pip freeze
Answer from negas on Stack OverflowAdd your virtual environment as Python kernel in this way (Make sure it's activated):
(venv)
$ ipython kernel install --name "local-venv-kernel" --user
Now, you can select the created kernel "local-venv-kernel" when you start Jupyter notebook or lab.
You could check the installed libraries using this code in a notebook cell:
!pip freeze
This has been answerd in this post:
don't use ! before pip command because it is executed as in command line, instead use the % sign to execute inside the virtual evironment of the current ipython kernel.
Python in terminal finds module, jupyter notebook does not
Module Not Found
Installed modules cannot be imported (ModuleNotFound error)
python - Module not found during import in Jupyter Notebook - Stack Overflow
How do I install a package in Jupyter Notebook?
What's the difference between pip install and python -m pip install?
Why do I get ModuleNotFoundError after pip install?
I'm pretty sure this issue is related and the answer there will help you: "ImportError: No module named" when trying to run Python script
tl;dr: the cwd of the notebook server is always the base path where you started the server, no matter was running import os os.getcwd() says. Use import sys sys.path.append("/path/to/your/module/folder").
I ran it with some dummy modules in the same structure as you had specified, and before modifying sys.path it wouldn't run and after it would.
Understand these two functions, and your problem will be solved.
# List the current work directory
os.getcwd()
# Change the current work directory
os.chdir()
Change the path, and import module, and have fun.
Sometimes it won't work. Try this:
import sys
# 'sys.path' is a list of absolute path strings
sys.path.append('/path/to/application/app/folder')
import file
Try the following:
pip3 install ipykernel --upgrade
python3 -m ipykernel install --user
Make sure that pandas is installed using pip3.
I was having a similar issue. I installed a text processing tool using pip3. The installation was successful and I was able to run the test-code from the terminal, however I was unable to execute the same code from jupyter notebook. Checked that the sys.version was 3.7.1 in notebook but the terminal version was 3.6.9.
The problem was resolved after executing the following commands and relaunching the notebook:
pip3 install ipykernel --upgrade
python3 -m ipykernel install --user
You can try installing numpy (or any other package for that matter available on pip) directly from your jupyter cell.
import sys
!{sys.executable} -m pip install numpy
Please see Jake's tutorial for more explanation.
If the package is installed sucessfully, you can add the path where the package is located either as an environment variable or in your notebook.
import sys
sys.path.append('/anaconda3/envs/gdd/lib/python3.7/site-packages')