A similar approach could work for virtualenvs or other Python environments.
#Conda install package to specific environment install#
Once you do this, switching to the myenv kernel will automatically activate the myenv conda environment, which changes your $CONDA_PREFIX, $PATH and other system variables such that !conda install XXX and !pip install XXX will work correctly.
# this is the critical part, and should be at the end of your script:Įxec python -m ipykernel in your kernel.json file, modify the argv field to look like this: "argv": [
Perhaps: for example, this github issue shows an approach to modifying shell variables as part of kernel startup.īasically, in your kernel directory, you can add a script kernel-startup.sh that looks something like this (and make sure you change the permissions so that it's executable): #!/usr/bin/env bash So, could we massage kernel specifications such that they force the two to match? Users/jakevdp/anaconda/envs/python3.6/bin/pythonĪs I mentioned, the fundamental issue is a mismatch between Jupyter's shell environment and compute kernel. Doing this can have bad consequences, as often the operating system itself depends on particular versions of packages within that Python installation.įor day-to-day Python usage, you should isolate your packages from the system Python, using either virtual environments or Anaconda/Miniconda - I personally prefer conda for this, but I know many colleagues who prefer virtualenv. It will always lead to problems in the long term, even if it seems to solve them in the short-term.įor example, if pip install gives you a permission error, it likely means you're trying to install/update packages in a system python, such as /usr/bin/python. If you installed Python any other way (from source, using pyenv, virtualenv, etc.), then use pip to install Python packagesįinally, because it often comes up, I should mention that you should never use sudo pip install. If conda tells you the package you want doesn't exist, then use pip (or try conda-forge, which has more packages available than the default conda channel). If you installed Python using Anaconda or Miniconda, then use conda to install Python packages. If you already have a Python installation that you're using, then the choice of which to use is easy:
In software, it's said that all abstractions are leaky, and this is true for the Jupyter notebook as it is for any other software.