简体   繁体   中英

Messed up with two python versions on linux

As I understood, I have two versions of python 2.7 installed on my machine. One is located in /usr/bin and another one is in /usr/local/bin . When I type python in the shell, it calls one in /usr/local/bin , and it doesn't have access to all the packages installed using apt-get and pip. I have tried to set up an alias, but when I type sudo python it still calls one in /usr/local/bin . I want to always use one in /usr/bin , since I have all the packages there. How do I do that?

you can easily have two python version in your machine. But first I recommend to install the Anaconda package.

And then you can create an environment with python 3 version

conda create --name test_env python=3 numpy pandas

In order to activate it, you need to write in your terminal

source activate test_env

More info here: https://conda.io/docs/using/envs.html

From what I understood,

  1. You have two version of python. One is in /usr/local/bin/python and another is in /usr/bin/python.
  2. In your current configuration default python -> /usr/local/bin/python
  3. You want to use the one that is in /usr/bin.

Update your ~/.bashrc and append this line at the end

alias python=/usr/bin/python

Then open a new terminal. Or do source ~/.bashrc in the current terminal

Run which python to see the location of the python executable. It will show you /usr/bin/python


Also, if you want to get packages in your current python (ie /usr/local/bin/python) you can use pip with that particular python version.

  1. Find pip location using which pip
  2. Assuming pip location is /usr/local/bin/pip /usr/local/bin/python /usr/local/bin/pip install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM