3

Without root access, how do I change the default Python from 3.5 to 2.7 for my specific user? Would like to know how to run Python scripts with Python 2 as well.

If I start up Python by running simply python then it runs 3.5.2. I have to specifically run python2 at the terminal prompt to get a version of python2 up.

If I run which python, then /data/apps/anaconda3/bin/python gets returned and I believe Python 2.7 is under /usr/bin/python.

This is on CentOS if that helps clarify anything

jfs
  • 374,366
  • 172
  • 933
  • 1,594
simplycoding
  • 2,488
  • 8
  • 39
  • 74
  • Possible duplicate of [Two versions of python on linux. how to make 2.7 the default](http://stackoverflow.com/questions/19256127/two-versions-of-python-on-linux-how-to-make-2-7-the-default) – MaLiN2223 Nov 11 '16 at 20:24
  • python 2.7 is the default on centos. Perhaps you should add an "anacoda" tag to this question because its more of a "why did anaconda mess up my centos" thing. The convention is that "python" is python 2 and "python3" is python 3. I'm not sure why they've messed with that but anything to attract anaconda users to your question would help. – tdelaney Nov 11 '16 at 20:43
  • General questions that would be useful: How did you install anaconda? Did you stick with the defaults or did you change your PATH variable or something? Are you running in a virtualenv when you hit the problem? – tdelaney Nov 11 '16 at 20:47
  • No idea how Anaconda was installed. I'm just another user, so I have no knowledge on the PATH variable and whatnot. – simplycoding Nov 11 '16 at 22:04

2 Answers2

2

You can add

alias python=python2.7

to your .bashrc file in home folder

Yevhen Kuzmovych
  • 7,193
  • 5
  • 23
  • 40
  • I don't use anaconda but it seems like they specifically want `python` to be python 3. It may be more appropriate to change the aliases in `/data/apps/anaconda3/bin` or change the order of that directory in your PATH variable. Likely there are other executables in that path that could be problematic. – tdelaney Nov 11 '16 at 20:45
  • I actually want `python` to be python 2 – simplycoding Nov 11 '16 at 22:11
  • @simplycoding Then `alias python=python2` – Yevhen Kuzmovych Nov 11 '16 at 22:14
0

If you are looking to change the python interpreter in anaconda from 3.5 to 2.7 for the user, try the command conda install python=2.7