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?

7
  • 2
    python -m pip install pandas should install it into the version of Python that python resolves to on the command line. Commented Jan 19, 2019 at 23:42
  • 1
    You should use something like conda or pyenv to manage different versions of python. Commented Jan 19, 2019 at 23:42
  • 1
    You can create symlinks to the appropriate pips on your system Commented Jan 19, 2019 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. Commented Jan 19, 2019 at 23:46
  • 1
    @busybear. I'm pretty sure ! will redirect to the shell, which will use whatever comes first on your path. Commented Jan 19, 2019 at 23:55

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
@CHAMI. Use /usr/bin. And the ... is not literal. I'm assuming you find the actual script.
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
Find the actual pip script for the python install you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.