1

On linux machine "Ubuntu 16.04.5 LTS", I have at least 3 versions of python installed: 2.7 , 3.5 and 3.6.8

I am having a problem especially between 3.6 and 3.5.

When working with jupyter notebook, I see that it's using 3.6.8 python version.

But when I try to install a package, pip installs it in 3.5 . The same issue is for python running in the terminal. It runs 3.6.8

Example :

Whether on jpyter or on terminal, I can't import the pandas package. import pandas is returning module not installed error message.

But when I check, I find the installation may have gone to python3.5 not 3.6.8

I install it with pip but I still get the same problem. I don't actually know how to solve this without removing everything and starting from the beginning because I have a very complicated package setup that took me long time to set up.

The solution here did not help too much because I dont have pip3.x on my computer.

Your thoughts?

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
smerllo
  • 3,117
  • 1
  • 22
  • 37
  • 2
    `python -m pip install pandas` should install it into the version of Python that `python` resolves to on the command line. – Peter Wood Jan 19 '19 at 23:42
  • 1
    You should use something like `conda` or `pyenv` to manage different versions of python. – 2daaa Jan 19 '19 at 23:42
  • 1
    You can create symlinks to the appropriate pips on your system – Mad Physicist Jan 19 '19 at 23:46
  • 1
    You can also call `pip` from your jupyter notebook using magic shell command: `!pip install pandas`. This should call the pip associated with that python installation. – busybear Jan 19 '19 at 23:46
  • 1
    @busybear. I'm pretty sure ! will redirect to the shell, which will use whatever comes first on your path. – Mad Physicist Jan 19 '19 at 23:55
  • @MadPhysicist It does, so it depends on the setup I suppose. If OP has environments setup, the correct `pip` will (should) be first in the path. But that might not be the case--worth trying though. – busybear Jan 20 '19 at 00:03
  • @busybear. OP clearly has 3.5 pip but Python 3.6 symlinked in /usr/bin – Mad Physicist Jan 20 '19 at 00:05

1 Answers1

1

Since you are trying to avoid reinstalling your complex setups, and they work pretty well as it is, using conda or even venv might not suit you too well.

However, you can always create appropriately named symlinks somewhere in your PATH to point to the correct versions of pip. So if you have ~/bin on your path, do something like

ln -s /usr/lib/python2.7/...pip ~/bin/pip2.7
ln -s /usr/lib/python3.5/...pip ~/bin/pip3.5
ln -s /usr/lib/python3.6.8/...pip ~/bin/pip3.6

If you have root access, you can even put the links directly into /usr/bin/ or wherever you prefer. Now you can just run pip2.7 or pip3.5 or pip3.6 and have things installed where you want.

But in the future, hopefully you will have learned from your headache and will use virtual environments.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
  • Good idea ! so if I got that well, I run this command on terminal : `sudo ln -s /usr/lib/python2.7/...pip /bin/pip2.7` (see that i typed /bin without ~). After doing that, I tried `pip2.7 install pandas` and got that error pip2.7: command not found. – smerllo Jan 20 '19 at 00:03
  • 1
    @CHAMI. Use /usr/bin. And the ... is not literal. I'm assuming you find the actual script. – Mad Physicist Jan 20 '19 at 00:07
  • I did replaced ~/bin with /usr/bin and run this : `sudo ln -s /usr/lib/python2.7/ pip /usr/bin/pip2.7` but got this : `ln: target '/usr/bin/pip2.7' is not a directory` – smerllo Jan 20 '19 at 00:12
  • 1
    Find the actual pip script for the python install you want. – Mad Physicist Jan 20 '19 at 00:39