0

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

  • Whats the output of echo $PATH? – heemayl Apr 25 '17 at 13:57
  • /home/john/anaconda3/bin:/home/john/.local/share/umake/bin:/home/john/bin:/home/john/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin – Eulerian Apr 25 '17 at 14:02
  • Ok I solved it by renaming the file name "python" inside anaconda3/bin – Eulerian Apr 25 '17 at 14:16
  • why would you do that? Please check my answer... – heemayl Apr 25 '17 at 14:16
0

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.

0

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

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.