4

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.

Raghu Venmarathoor
  • 858
  • 11
  • 28
  • As any user also root has a `.bashrc` where you can set the `PATH` variable appropriately. – cel Feb 27 '15 at 08:18
  • how about using a symlink? – Afriyandi Setiawan Feb 27 '15 at 08:20
  • @cel I've already added the PATH using /etc/environment file. I thought, it is enough. Do I have to add that path in .bashrc also? – Raghu Venmarathoor Feb 27 '15 at 08:22
  • @cel I'm sorry that I used the word root. Actually, I was using sudo to get root privileges. – Raghu Venmarathoor Feb 27 '15 at 08:28
  • 1
    Could be related: http://unix.stackexchange.com/questions/91541/why-is-path-reset-in-a-sudo-command – cel Feb 27 '15 at 12:45
  • See http://stackoverflow.com/q/257616/161801 – asmeurer Mar 02 '15 at 17:39
  • Thanks for your help guys. Actually, I was installing my script using sudo, which automatically made sudo python path to it's reference. That was the reason why it chose sudo python reference and ended up with problems in running it. I removed sudo from the installation script and for now, it works, as there is no issue in running the script as a user. – Raghu Venmarathoor Mar 03 '15 at 04:39

1 Answers1

2

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.

Community
  • 1
  • 1
kalu
  • 2,594
  • 1
  • 21
  • 22