Issue
So I have a virtual environment created with Anaconda
, and I've also installed it into Jupyter notebook as this link describes:
python -m ipykernel install --user --name=<my_env_name>
However, whenever I install something new onto my_env_name
, it doesn't work within the notebook. For example, I just did the following:
>>> pip install boto3
>>> import boto3
This works in the anaconda prompt.
However, if I try to do import boto3
in the notebook, I just get:
ModuleNotFoundError: No module named 'boto3'
Why isn't the libraries syncing up? I actually ran the ipykernel
command again as well to see if that would fix it, but nope. If I run !pip install boto3
within the notebook, I just get a bunch of "requirement satisfied already". What could be the reason causing this issue?
Edit:
While checking the sys.executable
I get:
C:\Users\MyUser\AppData\Local\Continuum\anaconda3\python.exe
But I probably should be getting this, correct?
C:\Users\MyUser\AppData\Local\Continuum\anaconda3\envs\my_env_name\python.exe
Solution
You may need to install kernel within the required environment using
python3 -m ipykernel install --user
and then install required libraries within this environment. Just make sure ipykernel
is installed in the virtualenv
If above solution does not work then you can try steps given below
Step 1: check the correct executable path of the anaconda environment. Go on command line, activate the conda environment then check the correct executable path for the environment.
conda activate {envronment name}
then on python console,
import sys
sys.executable
For instance on Linux it will be
/media/{username}/{path-to}/anaconda3/envs/{environment name}/bin/python
Step 2: correct the executable path for jupyter sessions From command line, check the path where kernel.json of your conda environment is located using below command
jupyter kernelspec list
For instance on Linux it will be:
/home/{username}/.local/share/jupyter/kernels/{environment name}
Open the kernel.json
located in that folder and replace the incorrect executable path, as shown below.
{
"argv": [
"REPLACE-THIS-WITH-THE-CORRECT-EXECUTABLE-PATH",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"display_name": "heterodimers",
"language": "python"
}
Answered By - Suhas_Pote
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.