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.pyex.py is run by anaconda3
python2.7 ex.pyex.py is run by python2.7
python3 ex.pyex.py is run by anaconda3
what I want to happen:
python ex.pyex.py is run by python2.7
python2.7 ex.pyex.py is run by python2.7
python3 ex.pyex.py is run by anaconda3
42 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/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/binThe /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/bindirectory from thePATH, 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/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'You can do:
echo "export PATH='<above_path_here>'" >>~/.bashrcNot 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.