I tried installing Python 2.7 without root on a remote linux machine. I ran the commands
./configure prefix=/
make install DESTDIR=/xxx/yyy/
You should have prefix=/xxx/yyy. With prefix=/, it tries to install the libraries to /lib/python2.7, rather than /xxx/yyy/lib/python2.7.
I wrote a script that installs Python 2 (which is missing the convenience faculties provided by Python 3 for user installations) and Pip 2 into a user directory so that a standard user can be administrator over its modules etc.
#!/bin/bash
VERSION="2.7.11"
BUILDDIR=~/"build/python"
INSTALLDIR=~/"python/Python-$VERSION"
mkdir -p ${BUILDDIR}
cd ${BUILDDIR}
if [ ! -f $BUILDDIR/Python-$VERSION.tgz ]
then
wget https://www.python.org/ftp/python/$VERSION/Python-$VERSION.tgz
tar zxfv Python-$VERSION.tgz
fi
find $BUILDDIR -type d | xargs chmod 0755
cd Python-$VERSION
mkdir -p ${INSTALLDIR}
./configure --prefix=${INSTALLDIR}
make && make install
# Append to user PATH or create symbolic link to .local/bin
# [[ ":$PATH:" != *":$HOME/python/Python-$VERSION/bin:"* ]] && printf "export PATH=$HOME/python/Python-$VERSION/bin:$PATH\n" >> ~/.bashrc
if [ ! -d ~/.local/bin ]; then mkdir -p ~/.local/bin; fi
ln -s ~/python/Python-"$VERSION"/bin/python ~/.local/bin/
source ~/.bashrc
# Install local pip
cd ..
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py -O - | python - --user
[[ ":$PATH:" != *":$HOME/.local/bin:"* ]] && printf "export PATH=$HOME/.local/bin:$PATH\n" >> ~/.bashrc
# Install modules like this:
# pip install --target="$HOME/.local/lib/python$VERSION/site-packages"
# Add those modules to PYTHONPATH
[[ ":$PYTHONPATH:" != *":$HOME/.local/lib/python$VERSION/site-packages:"* ]] && printf "export PYTHONPATH=$HOME/.local/lib/python$VERSION/site-packages:$PYTHONPATH\n" >> ~/.bashrc
source ~/.bashrc
Caveat: This script is admittedly opinionated in that it will append a few lines to your ~/.bashrc
for the PATH ENV variable. If this is not desired, simply comment the related lines in the script.
Case: The service file generator for Airprint service files for use in Avahi does not support Python 3. For the purpose of keeping the system clean, I just install a local version of Python 2 and run airprint-generate.py
followed by deleting the whole install (saves space on a small Raspberry Pi Zero W).
I just install python2.7.5 without admin right. I think the command should be:
./configure prefix=/xxx/yyy
make install
and then you should add the path /xxx/yyy/bin in .bashrc as:
PYTHONPATH=/home/songmeixu/python/bin
export PATH=$PYTHONPATH:$PATH
Instead of building from source manually, I'd suggest letting linuxbrew do the build for you. DigitalOcean has a nice tutorial on installing linuxbrew. Once that's complete, you can just say brew install python
and have a nicely managed python installation, including pip.
Don't compile, get the pre-built binary from ActiveState.