A note on NBDev and PIP aliases

You can get errors importing NBDev in a Jupyter notebook if you alias pip→pip3, even in a base environment setup w/ nb_conda, and even after a seemingly successful pip install and import test in terminal.

I recently had issues importing nbdev in a jupyter notebook (ModuleNotFoundError: No module named ‘nbdev’). This was weird, because I was able to import nbdev in terminal, in my base conda environment – which I was also using in Jupyter. This was a newly setup base conda environment on a newly-installed operating system.

Turns out: I set my terminal to alias the pip command to /usr/local/bin/pip3, since I have no use for python 2 and want pip to default to python 3. That overrode the conda environment’s pip, so anything installed with pip went to my system python 3 directory, not the base conda evironment.

I don’t have a fix for the pip→pip3 issue system-wide, but if you don’t alias them (do not have the line alias pip=/usr/local/bin/pip3 active in your ~/.zshrc (on MacOS) file), you should be able to use pip to install to your active conda environment – provided you installed pip there via conda install pip. You can use which pip in terminal to check where it’s loading pip from.

  • I think you have to install pip in each new conda environment, but I’m not sure if conda won’t just automatically install it when you make a new environment bc I haven’t noticed problems with it in the past.

This cost a few hours, python package management can be confusing. Like a lot of things, it’s simple once you understand it, but it’s magic until then. This may/not be a similar issue to post 73 in the main discussion.