问题
I isolate my data science projects into virtual environments using pipenv
. However, running a Jupyter notebok does not access the local environment and uses the default IPyKernel. I've seen that you can register virtual environments from within the environment, but this requires installing the ipykernel
package which itself requires Jupyter!
Is there anyway to avoid this and just use a single Jupyter install for all virtual environments?
回答1:
Generally, you'd install jupyter once and do the following in your virtual environments:
pip install ipykernel
python -m ipykernel install --user
This isn't enough when you're running multiple Python versions.
There's a guide here that tries to address this:
https://medium.com/@henriquebastos/the-definitive-guide-to-setup-my-python-workspace-628d68552e14
It's not 100% failsafe, but it can help you avoid reinstalling jupyter notebook all the time.
回答2:
I found a workaround that I'd appreciate feedback on. I changed pipenv to install virtual environments into the working directory by add to .bashrc
/.bash_profile
:
export PIPENV_VENV_IN_PROJECT=1
Now when opening a Jupyter notebook, I simply tack on the virtual environment's packages to the Python path:
import sys
sys.path.append('./.venv/lib/python3.7/site-packages/')
Is this a terrible idea?
来源:https://stackoverflow.com/questions/52566337/do-i-need-to-install-jupyter-notebook-in-every-virtual-environment