python - Python2.7 / Pip2.7 install in Centos6: root does not see /usr/local/bin
2014-07
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?
I'm not sure why I am having trouble installing the Python Module Bitarray on my Ubuntu 8.10 machine.
dan@Tower:~/py$ tar xzf bitarray-0.3.5.tar.gz
dan@Tower:~/py$ cd bitarray-0.3.5
dan@Tower:~/py/bitarray-0.3.5$
dan@Tower:~/py/bitarray-0.3.5$ python setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-i686-2.5
creating build/lib.linux-i686-2.5/bitarray
copying bitarray/test_bitarray.py -> build/lib.linux-i686-2.5/bitarray
copying bitarray/__init__.py -> build/lib.linux-i686-2.5/bitarray
running build_ext
building 'bitarray._bitarray' extension
creating build/temp.linux-i686-2.5
creating build/temp.linux-i686-2.5/bitarray
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.5 -c bitarray/_bitarray.c -o build/te
mp.linux-i686-2.5/bitarray/_bitarray.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-i686-2.5/bitarray/_bitarray.o -o build/lib.linux-i686-2.5/bitarray/_bitarray.so
running install_lib
creating /usr/lib/python2.5/site-packages/bitarray
error: could not create '/usr/lib/python2.5/site-packages/bitarray': Permission denied
dan@Tower:~/py/bitarray-0.3.5$ sudo python setup.py install
[sudo] password for dan:
running install
running build
running build_py
running build_ext
running install_lib
creating /usr/lib/python2.5/site-packages/bitarray
copying build/lib.linux-i686-2.5/bitarray/_bitarray.so -> /usr/lib/python2.5/site-packages/bitarray
copying build/lib.linux-i686-2.5/bitarray/test_bitarray.py -> /usr/lib/python2.5/site-packages/bitarray
copying build/lib.linux-i686-2.5/bitarray/__init__.py -> /usr/lib/python2.5/site-packages/bitarray
byte-compiling /usr/lib/python2.5/site-packages/bitarray/test_bitarray.py to test_bitarray.pyc
byte-compiling /usr/lib/python2.5/site-packages/bitarray/__init__.py to __init__.pyc
running install_egg_info
Writing /usr/lib/python2.5/site-packages/bitarray-0.3.5.egg-info
dan@Tower:~/py/bitarray-0.3.5$ python -c 'import bitarray; bitarray.test()'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "bitarray/__init__.py", line 13, in <module>
from _bitarray import _bitarray, bits2bytes, _sysinfo
ImportError: No module named _bitarray
The module is installed correctly, but it tries to import the local version if you are in ~/py/bitarray-0.3.5
. This doesn't work because you don't have _bitarray.so in the source code tree (you would need python build_ext -i
to make it work). Just go to some other directory and run python from there, it will work.