简体   繁体   中英

How To Set Sources For Jupyter Notebooks

I've just bought a new computer, and can't remember/don't know how I had Jupyter notebooks set up on my old machine. Specifically, how do you tell Jupyter about sources.
If I have a conda environment called django, and I do source activate django followed by jupyter notebook , I end up with a notebook, but then when I do from django.http import HttpResponse I get the error message

ModuleNotFoundError: No module named 'django'

Which is bizarre (I think), because Django is definitely installed in the Django environment.

How do I set up my Jupyter notebooks so that they know about the various sources that I want them to know about?

It is very likely your conda environment django doesn't have iPython Kernel installed which jupyter notebook needs. You can run jupyter notebook without activating a conda environment as notebook allows you to select any conda environment with ipykernel installed.

Try:

  1. run in terminal : source activate django
  2. run in terminal : conda install ipykernel
  3. run in terminal : source deactivate
  4. run in terminal : jupyter notebook
  5. select django for your kernel 在此处输入图片说明

I create a kernel for each of my virtual environments. On MacOS Jupyter kernels are located here $HOME/Library/Jupyter/kernels . Make sure ipykernel is installed in your virtual env.

So $HOME/Library/Jupyter/kernels/myenv/kernel.json looks like:

{
 "env": { "VIRTUAL_ENV": "/Users/<User>/<myenv>" },
 "argv": [ "/Users/<User>/<myenv>/bin/python3", "-m", "ipykernel", "-f", "{connection_file}" ],
 "display_name": "My Virtual Env",
 "language": "python"
}

Found the answer here .

source activate django
conda install ipykernal
python -m ipykernel install --user --name django --display-name "Python (Django)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM