10

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

0

5 Answers 5

15

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
10

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.

2
  • I did this, but then it installed the bin/share/lib files in /xxx/yyy/xxx/yyy. I ended up renaming the paths, to reflect the directory structure that I wanted (certainly not that redundant path!) and I am hoping that it will cause no path conflicts.
    – ktm5124
    Apr 28, 2011 at 20:30
  • 3
    @ktm5124: Don't supply a DESTDIR if you've already configured prefix. In fact, users shouldn't need to use DESTDIR at all.
    – Rufflewind
    Jan 3, 2015 at 13:27
4

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

5
  • Why doesn't everyone do this? Is there a catch? Aug 11, 2012 at 22:25
  • 2
    @GabrielFair - the community license has certain restrictions... see activestate.com/activepython/license-agreement Aug 13, 2012 at 17:25
  • 1
    This is simplest! And with pip, I installed all my packages I needed.
    – Yin Zhu
    Jul 21, 2013 at 7:21
  • It seems they do not supply the latest version. At time of writing, AS supplied 3.4.1 and newest version is 3.4.3
    – hilcharge
    Aug 13, 2015 at 7:10
  • If you need a standard build, and precompiled binaries are available for your platform, this is a nice solution; but the answer should probably outline when this might not be what you need (i.e. you can't find binaries for your specific platform; or you need a custom build for some reason, such as requising a newer one that the available precompiled binaries).
    – tripleee
    Mar 24, 2019 at 12:19
2

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

6
  • The quoting is wrong, but happens to work as long as your home directory path doesn't contain any shell metacharacters. The correct quoting would put ~ outside any double quotes, but then always use double quotes around the variable interpolations. See also When to wrap quotes around a shell variable?
    – tripleee
    Mar 24, 2019 at 12:22
  • Also `pwd` is an expensive and roundabout way of saying . if you don't specifically need an absoulte path.
    – tripleee
    Mar 24, 2019 at 12:24
  • You might want to put the printf statements to update .bashrc in a conditional, so as to avoid adding these lines again if you already ran this script before.
    – tripleee
    Mar 24, 2019 at 12:26
  • @tripleee probably a good idea to open a chat for all of these comments: chat.stackoverflow.com/users/874188/tripleee Mar 24, 2019 at 12:27
  • Sorry, not in a place where I can conveniently access chat. If you can wait until Monday, I'll be happy to converse with you about these suggestions.
    – tripleee
    Mar 24, 2019 at 12:29
0

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.

2
  • 1
    Note that the linked tutorial assumes sudo acces.
    – JorgeGT
    Oct 30, 2014 at 21:32
  • The linuxbrew readme (github.com/Linuxbrew/brew - note updated URL) has brief, easy instructions, with no root/sudo required.
    – Jacktose
    Jun 7, 2017 at 19:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.