Glam Prestige Journal

Bright entertainment trends with youth appeal.

I installed anaconda3 on Ubuntu. Everything is running flawlessly except for one small issue. When using the command "python" to run some arbitrary python file, it runs python3 using anaconda instead of the native 2.7 python interpreter. How can I change that?
In other words :
what is happening right now:

python ex.py

ex.py is run by anaconda3

python2.7 ex.py

ex.py is run by python2.7

python3 ex.py

ex.py is run by anaconda3

what I want to happen:

python ex.py

ex.py is run by python2.7

python2.7 ex.py

ex.py is run by python2.7

python3 ex.py

ex.py is run by anaconda3

4

2 Answers

As seen from the output of echo $PATH:

/home/john/anaconda3/bin:/home/john/.local/share/umake/bin:/‌​home/john/bin:/home/‌​john/.local/bin:/usr‌​/local/sbin:/usr/loc‌​al/bin:/usr/sbin:/us‌​r/bin:/sbin:/bin:/us‌​r/games:/usr/local/g‌​ames:/snap/bin

The /home/john/anaconda3/bin directory comes first and as the relevant python(analogous to python2) and python3 binaries are present in the directory, all your python scripts are being interpreted by binaries in that directory, not the system-wide ones that come with python-minimal (python2) and python3-minimal (python3) packages, and present in /usr/bin directory that comes later in your PATH.

You need to:

  • either use the full path to the systems' ones

Or

  • drop the /home/john/anaconda3/bin directory from the PATH, append the following to your ~/.bashrc:

    export PATH='/home/john/.local/share/umake/bin:/‌​home/john/bin:/home/‌​john/.local/bin:/usr‌​/local/sbin:/usr/loc‌​al/bin:/usr/sbin:/us‌​r/bin:/sbin:/bin:/us‌​r/games:/usr/local/g‌​ames:/snap/bin'

    You can do:

    echo "export PATH='<above_path_here>'" >>~/.bashrc

    Not sure if you want to keep `/home/john/.local/share/umake/bin, make your choice.


Just for the sake of completeness, both python2 and python3 are actually symlinked to the respective latest binaries present on the system.

In that case you need to deactivate conda environment.
The best advice is activate your conda environment only when you need (remove conda activate from your .bashrc file) and thus, python system will be use in the common tasks of your OS without issues or unexpected behaviors.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy