I installed Anaconda in a Google Cloud Compute environment and can use it successfully from the shell as a normal user:
curt@lamp-v5mi:~$ python
Python 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Mar 9 2015, 16:20:48)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
However, when I start an interpreter via sudo python
, anaconda is not the interpreter used, and I would like it to be.
curt@lamp-v5mi:~$ sudo python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Confusingly, when I start a shell as root and then start an interpreter, anaconda is the interpreter used.
curt@lamp-v5mi:~$ sudo -s
root@lamp-v5mi:/home/curt# python
Python 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Mar 9 2015, 16:20:48)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
I have export PATH="/anaconda/bin:$PATH"
in both the root's and my normal account's .bashrc
files. At first I thought the issue was sudo python
not actually starting a root shell, and thus the export PATH="/anaconda/bin:$PATH"
not actually being done. But when from my normal account I do sudo echo $PATH
, it shows anaconda in there:
curt@lamp-v5mi:~$ sudo echo $PATH
/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
The anaconda installation was installed as root in /anaconda
and I did a chmod -R 770 /anaconda
to make it accessible to normal users, but I don't think this problem has anything to do with that.
How can I get anaconda to be the default interpreter when run from a sudo
command line?
You almost got everything right. The only error is sudo echo $PATH
, where $PATH is substitued BEFORE being sent to sudo, so it's your user PATH not your "sudoed" PATH that's displayed.
Note that your sudo implementation and configuration may change the PATH variable, as I can read in a "man sudo" (found from the Internet as I don't have sudo):
PATH
May be overridden by the security policy.
So, in your "sudoed" PATH, there's probably no /anaconda/bin/
You may test this using sudo env | grep PATH
.
To allow or change the PATH environment variable in your sudoed environment, I only can direct you to your man sudo
, again: I'm not a sudo user.
The only thing I can drop you is sudo $(which python)
, as in sudo echo $PATH
, the $(which python)
will be executed by your user, resulting in /anaconda/bin/python
, so actually running sudo /anaconda/bin/python
which is another "solution".
To conclude, I should warn you that you probably don't want to run Python as root, there is almost no valid reason to do this, so your question is probably an XY problem: You got a first problem, you concluded by yourself it can be resolved by running Python as root, you tried sudo, got hit by sudo changing your PATH
, then posted your "2nd level" problem here. What is your "real problem" ? The one that triggered the "Hum, I should try with sudo" ?