ktm5124
ktm5124

Reputation: 12123

Installing Python 2.7 without root

I tried installing Python 2.7 without root on a remote linux machine. I ran the commands

./configure prefix=/  
make install DESTDIR=/xxx/yyy/ 

where /xxx/yyy/ is a directory for which I have read-write access.

I ran into a problem at the end. It said:

building dbm using gdbm INFO: Can't locate Tcl/Tk libs and/or headers

Python build finished, but the necessary bits to build these modules were not found: _tkinter bsddb185 dl imageop sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module's name.

running build_scripts running install_lib creating /lib/python2.7 error: could not create '/lib/python2.7': Permission denied

Did I take the correct steps in installing it without root access? (i.e., my configure and make commands?) Can anyone tell me why it would not install properly?

Thanks,
ktm

Upvotes: 10

Views: 24498

Answers (5)

Jonathan Komar
Jonathan Komar

Reputation: 3086

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).

Upvotes: 2

Jeff Hammerbacher
Jeff Hammerbacher

Reputation: 4246

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.

Upvotes: 0

SoLoMoN
SoLoMoN

Reputation: 151

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

Upvotes: 15

Sridhar Ratnakumar
Sridhar Ratnakumar

Reputation: 85452

Don't compile, get the pre-built binary from ActiveState.

Upvotes: 4

Jessica
Jessica

Reputation: 6987

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.

Upvotes: 10

Related Questions