Change default python to anaconda's python in

2019-05-11 18:40发布

问题:

I've installed python 2.7 in my system and I've installed Anaconda also. Right now, I am using python's anaconda and it works perfect. Unfortunately, I wanted to use anaconda's python to be run using root. The issue is that I was unable to change the python path for root.

If I type "which python" from terminal , I am able to get this result:

/home/myuser/anaconda/bin/python

If I type "sudo which python" from terminal, the result is :

/usr/bin/python

I have installed anaconda in a directory accessible by root (changed during installation) and I've already added it's path to /etc/environment(added /usr/anaconda/bin to PATH in environment).

How do I change the default python path of root(I use sudo command to get root privileges)?

I'm using ubuntu 12.04.

回答1:

You can explicitly call the python install you'd like to run:

sudo /opt/anaconda/bin/python

See https://askubuntu.com/questions/477987/two-python-distributions-sudo-picking-the-wrong-one.