Running 3.5 in J-Nb vs 3.6 in shell

So this is probably something stupid, but I’m having trouble running Python 3.6 inside my notebooks locally. I’m getting the syntax error screen when trying to import things as noted on other threads here.

When I check my version in the shell, all seems fine:

But then when I check my version inside jupyter notebook, it’s running 3.5 instead of the conda 3.6 version:

So I’ve done some googling and python developers tend to get extremely ‘hand wavy’ with their environment solutions (“So then I just dingle-jab my framostat. Easy.”) So I was wondering if anybody had any advice for me here. I feel sure there’s some way to configure this, or at least find the root cause of it. Any help in understanding this would be helpful. (Environment issues in Ruby are much easier for me) For me, this is much more about de-mystifying things than it is about running notebooks locally as opposed to on AWS. On AWS everything goes fine, but I’d like the freedom to develop locally until I’m ready to actually train/test/etc.

I believe that the python version that you get in the notebook is whatever python version the shell was where you started jupyter notebook, based on a very very few tests.

It doesn’t seem like you have this added to your path in the terminal you are running the jupyter notebook from:
export PATH="/home/<usr_name>/anaconda3/bin:$PATH"

This is what my path looks like:

['', '/home/radek/anaconda3/envs/fastai/lib/', '/home/radek/anaconda3/envs/fastai/lib/python3.6', '/home/radek/anaconda3/envs/fastai/lib/python3.6/lib-dynload', '/home/radek/anaconda3/envs/fastai/lib/python3.6/site-packages', '/home/radek/anaconda3/envs/fastai/lib/python3.6/site-packages/IPython/extensions', '/home/radek/.ipython']

BTW you might also want to do which jupyter before running the jupyter notebook command. I think this might give us some additional useful info.

BTW hello to a fellow rubyist :wink:

Make sure you install jupyter notebook. If you create a new environment but didn’t install jupyter. You will still able to start notebook but it actually calls notebook from your root environment instead of the conda env.

1 Like

You should run the following commands to ensure which Python is being used

which python


which jupyter


Then inside the notebook run this

import sys

This tells you which python is being used. Based on the path that you are showing it looks like Pythin 3.5 would run. You could run the jupyter notebook from the conda environment manually. So if your conda environment is named fastai then you could run something like


This should run the conda environment’s jupyter. If not, check whether you activated the conda environment by running something like conda activate fastai from the root of your conda environment.

Probably good for some clarification here. I’m not running a lesson notebook, I’ve started my own project that I plan to deploy one day. So I don’t know how much that will change things.

Here are the whichs requested:

    brianh@cenote:~/code/set-game$ which python
    brianh@cenote:~/code/set-game$ which jupyter

I tried to run conda activate fastai, but got this blurb:

    CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
    If your shell is Bash or a Bourne variant, enable conda for the current user with

        $ echo ". /home/brianh/anaconda3/etc/profile.d/" >> ~/.bashrc

    or, for all users, enable conda with

        $ sudo ln -s /home/brianh/anaconda3/etc/profile.d/ /etc/profile.d/

    The options above will permanently enable the 'conda' command, but they do NOT
    put conda's base (root) environment on PATH.  To do so, run

        $ conda activate

    in your terminal, or to put the base environment on PATH permanently, run

        $ echo "conda activate" >> ~/.bashrc

    Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
    your ~/.bashrc file.  You should manually remove the line that looks like

        export PATH="/home/brianh/anaconda3/bin:$PATH"

    ^^^ The above line should NO LONGER be in your ~/.bashrc file! ^^^

After following the instructions in the blurb, but before running conda activate fastai, I’m now getting a no module found 'torch' error instead of the original error, so I think that part fixed the python version mess. Now after running conda activate fastai I’m getting a no module named 'fastai' in my notebook. I’ll see if I can figure that one out, but I’ll post again here if I run out of luck.

Thanks everyone!