49

I extracted, configured and used make for the installation package in my server.

However, I could not use make install. I get the error

[~/wepapps/python/Python-2.6.1]# make install
/usr/bin/install -c python /usr/local/bin/python2.6
/usr/bin/install: cannot create regular file `/usr/local/bin/python2.6': Permission denied
make: *** [altbininstall] Error 1

I run the folder with

chmod +x Python-2.6.1

I get still the same error.

How can I run make install without sudo access?

6 Answers 6

111

How can I install to a path under my home directory?

mkdir /home/masi/.local

cd Python-2.6.1
make clean
./configure --prefix=/home/masi/.local
make
make install

Then run using:

/home/masi/.local/bin/python

Similarly if you have scripts (eg. CGI) that require your own user version of Python you have to tell them explicitly:

#!/home/masi/.local/bin/python

instead of using the default system Python which “#!/usr/bin/env python” will choose.

You can alter your PATH setting to make just typing “python” from the console run that version, but it won't help for web apps being run under a different user.

If you compile something that links to Python (eg. mod_wsgi) you have to tell it where to find your Python or it will use the system one instead. This is often done something like:

./configure --prefix=/home/masi/.local --with-python=/home/masi/.local

For other setup.py-based extensions like MySQLdb you simply have to run the setup.py script with the correct version of Python:

/home/masi/.local/bin/python setup.py install
Sign up to request clarification or add additional context in comments.

3 Comments

If you do not have setuptools in your system, please, see the post stackoverflow.com/questions/624671/…
Don't know about 2.6.X, but at least 2.7.9 and 3.x do not have a makefile before running the ./configure script. So maybe move "make clean" below the first call to configure?
Updated instructions for python3.x as of 20250202; stackoverflow.com/a/79406851/438758
43

As of year 2020, pyenv is the best choice for installing Python without sudo permission, supposing the system has necessary build dependencies.

# Install pyenv
$ curl https://pyenv.run | bash

# Follow the instruction to modify ~/.bashrc

# Install the latest Python from source code
$ pyenv install 3.8.3

# Check installed Python versions
$ pyenv versions

# Switch Python version
$ pyenv global 3.8.3

# Check where Python is actually installed
$ pyenv prefix
/home/admin/.pyenv/versions/3.8.3

# Check the current Python version
$ python -V
Python 3.8.3

3 Comments

If after the first line one runs into pyenv: command not found please consider my comments here.
The most convenient approach by far. One may ran into issues with read-only TMPDIR locations, export a new env. variable export TMPDIR="/home/USERNAME/temp". Installing <3.8.0 may also result in errors caused by missing _ctypes which can be solved only via installing libffi-dev issue31652.
When running into the problem of @GonçaloPeres龚燿禄, there should be a directory ~/.pyenv/, just run ~/.pyenv/bin/pyenv instead or add ~/.pyenv/bin to your PATH
4

Extending bobince answer, there is an issue if you don't have the readline development package installed in your system, and you don't have root access.

When Python is compiled without readline, your arrow keys won't work in the interpreter. However, you can install the readline standalone package as follows: Adding Readline Functionality Without Recompiling Python

On the other hand, if you prefer to compile python using a local installation of readline, here's how.

Before doing as bobince was telling, compile and install readline. These are the steps to do so:

Then, add this line to your .bash_profile script:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.local/lib

Last, but not least, execute the following command

export LDFLAGS="-L$HOME/.local"

I hope this helps someone!

Comments

1

You can't; not to /usr, anyway. Only superusers can write to those directories. Try installing Python to a path under your home directory instead.

3 Comments

What is "a path under my home directory"?
How can I install to a path under my home directory?
Take a look at the documentation on installing ( docs.python.org/using/unix.html ), particularly the part about paths and files.
0

I could solve this issue by using conda, assuming a virtual environment is enough for your application. After installing conda on your system, you can run

conda create -n myenv python=3.8.11

to create a Python environment with a specific version under your user. Using the -p flag you can also set the path of the environment to any directory you have access to.

In case you don't want to use the default Anaconda database, you can use the community mantained conda-forge instead.

You are able to create these environments without sudo access because conda installs binaries already compiled to your architecture. You don't need to build anything from source, therefore you don't need to install any build dependencies.

Comments

0

As of 20250202, this answer still works with extremely minor tweaks. Copy pasting my setup to benefit the next guy.

# download python source; https://www.python.org/downloads/source/
# please edit correct version in the commented code
# wget https://www.python.org/ftp/python/3.12.8/Python-3.12.8.tgz

# get into the directory containing the `configure`
# tar -xvf Python-3.12.8.tgz
# cd Python-3.12.8

mkdir -p $HOME/bin/.local
./configure --prefix=$HOME/bin/.local
make
make install

# add $HOME/bin/.local/bin to $PATH
export PATH="$HOME/bin/.local/bin:$PATH"

# check that you have the correct binary
which python3

# check version
python3 --version

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.