Python2.7 / Pip2.7 install in Centos6: root does not see /usr/local/bin

8,491

this stackoverflow entry probably explains what you are seeing. pixelbeat's suggests you alias sudo to set your environment each time it is called:

alias sudo='sudo env PATH=$PATH'

That workaround should resolve your issue. Personally, I prefer aliasing python2.7 and pip2.7.

Share:
8,491

Related videos on Youtube

Erotemic
Author by

Erotemic

?

Updated on September 18, 2022

Comments

  • Erotemic
    Erotemic almost 2 years

    I am trying to install Python2.7 in Centos 6. It's a pain as centos6 ships with python26 and yum is dependent on it. Furthermore yum does not seem to have python2.7

    I ended up building it from source:

        wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
        gunzip Python-2.7.6.tgz
        tar -xvf Python-2.7.6.tar
        cd Python-2.7.6
        ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
        make 
        sudo make altinstall
        cd ~
    

    This installed python2.7 to /usr/local/bin and I can use it. But I cannot call it with sudo unless I specify the whole pathname

    To install pip I had to do:

        wget https://bootstrap.pypa.io/get-pip.py
        sudo /usr/local/bin/python2.7 get-pip.py
    

    Now whenever I want a package I have to call

        sudo /usr/local/bin/pip2.7 install somepackage
    

    Is there a clean way to be able to run:

        sudo pip2.7 install somepackage
    

    without having to specify the absolute path? Is a symlink into /usr/bin safe?

  • Cfinley
    Cfinley almost 10 years
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
  • verboze
    verboze almost 10 years
    good point. answer updated.