-1

When I run python on RHEL, I automatically use Anaconda3:

Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

When I sudo python, it defaults to python 2.7.

Python 2.7.5 (default, Sep 12 2018, 05:31:16)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

"which python" vs "sudo which python" gives:

/opt/anaconda3/bin/python

/bin/python

How can I make sudo commands run Anaconda distribution of python. Is there any risk of changing this?

Can I make the change permanently, or do I just run python from sudo using the full Anaconda path?

smackenzie
  • 2,880
  • 7
  • 46
  • 99
  • have you tried `conda python` ? – sahasrara62 Jun 20 '19 at 09:30
  • sudo cant find conda, not in its path – smackenzie Jun 20 '19 at 09:36
  • sudo /opt/anaconda3/bin/python works – smackenzie Jun 20 '19 at 09:37
  • Possible duplicate of [How to set Python3.5.2 as default Python version on CentOS?](https://stackoverflow.com/q/45542690/608639); and others like [Unable to set default python version to python3 in ubuntu](https://stackoverflow.com/q/41986507/608639), [How to update-alternatives to Python 3 without breaking apt?](https://stackoverflow.com/q/43062608/608639), etc. – jww Jun 20 '19 at 12:50
  • This is more of an issue with different python environments being defaulted under root sudo access, than via normal account – smackenzie Jun 20 '19 at 13:00

1 Answers1

1

Your python version and installation location for root is different. If you want to use /opt/anaconda3/bin/python , there are different ways: You can add alias python="/opt/anaconda3/bin/python" to your .bashrcfile of root user and re login or source this .bashrc.

Other way is to use #!/opt/anaconda3/bin/python in your python code when you run it from root user so that is uses your anaconda distribution.

Point is, you have to use /opt/anaconda3/bin/python as your python binary.

You mayalso remove python2.7 from your root user and add /opt/anaconda3/bin/python in your PATH env variable.

Also, you can add /opt/anaconda3/bin/python in your PATH environment variable and use python3 instead of python from root user. or you can use /opt/anaconda3/bin/python instead of python

Make sure the permissions and owner ship of paths are good without conflicts among users.

deosha
  • 972
  • 5
  • 20