5

I had python 2.6 in my server to begin with. Then I downloaded python 2.7 and installed using make and make altinstall. When I try just python in the terminal it opens up python 2.7 but sudo python opens up 2.68. all the commands like virtualenv pip use python 2.68

1
  • Probably because $PATH differs between you and root.
    – Aya
    May 26 '13 at 16:02
12

Because sudo XYZ basically means "run XYZ as some other user (root by default)". That user may have a different set of environment variables, including $PATH.

To confirm this, compare the output of the following:

env | grep PATH
sudo env | grep PATH
1
  • Thanks. That seems to be the case. How do I ensure the path are same?
    – user1743992
    May 26 '13 at 16:53
2

The python Version of user:

~> python --version
Python 3.6.2 :: Continuum Analytics, Inc.

The python version of SUDO:

~> sudo python --version
Python 2.7.13

If you want to execute the same version of python when using sudo, you may try:

~> sudo env "PATH=$PATH" python --version
Python 3.6.2 :: Continuum Analytics, Inc.
1
  • how to make those changes permanent?
    – shashwat
    May 6 '19 at 9:15
0

Check the outputs of which python and sudo which python, they should be different. If so, check your $PATH for root and your normal user as noted by others.

0

As was suggested, check your path. If that does not work, check your .bashrc in your home directory. A standard way to use a different python version is to use an alias for python (assigned to /usr/local/bin/python2.7 for example) in the .bashrc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy