Installing fastai on Ubuntu using pip and virtualenv

Yes, I know anaconda is recommended. But if you’ve already been using python+pip for a while, then anaconda may interfere with your already installed software (actually, it’s surprisingly hard to find information on whether anaconda and pip can coexist…)

On Ubuntu 18.04 LTS, a simple pip install fastai doesn’t quite work, because pip will fetch the newest version of numpy, which conflicts with the version in the Ubuntu repositories (1.16 vs 1.13). So instead you want to put fastai in its own virtual environment.

This worked for me (having installed CUDA on a previous occasion):

pip install virtualenv
python -m virtualenv fastai_env
source fastai_env/bin/activate
# your prompt should change to show (fastai_env) at the start
pip install fastai # wait a long time while stuff gets downloaded!
pip install ipykernel
python -m ipykernel install --user --name fastai_env --display-name "Python3 (fastai_env)"
deactivate # prompt changes back to normal

Then within Jupyter, when you open a notebook for the first time, you’ll need to use the “kernel” menu to change over to the fastai environment.

More information about working with virtual environments:


2 Likes

Just in case you haven’t found that one. They can coexist, but maybe not in a way you’d expect. Pip can easily be run inside conda. You can use conda to manage python versions, install some libraries and then use pip for the rest. That will totally work. What will not work are packages you installed before installing conda, but that’s because the python you run after that (installed by conda) does not have the same site-packages directory in sys.path. Ofc, you can install them again after installing conda, but they will be downloaded, unpacked, and possibly compiled (in case they do not have wheels) again.

1 Like