How to install python as a user
Solution 1
Use virtual environments. This allows you to make unlimited amounts of virtual python environments, so you can easily use different sets of packages for different projects. Install the following:
sudo apt-get install python-virtualenv
Then:
sudo pip install virtualenvwrapper
Then, append the following to your bashrc file:
export WORKON_HOME=~/Envs
mkdir -p ~/Envs
source /usr/local/bin/virtualenvwrapper.sh
Then, suppose we want to make a virtual environment called "test-env" we can execute:
mkvirtualenv test-env
To use it:
workon test-env
From within this environment you can then pip install anything (without sudo!).
To exit your virtual environment:
deactivate
Solution 2
Yes you can do that. You can install python into your home directory. So you don't need to have root permissions but little bit ground work needed to do so. Follow the answer.
Open your terminal , assume you are installing python to your home directory.
mkdir python
cd python
wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar -xvf Python-2.7.6.tgz
cd Python-2.7.6
Then now, while doing configure
, you must mention that where you are trying to install it.
so like
./configure --prefix=$HOME/python
make
make install
So right now your python has installed in your home at python named directory. so your system must now that the python which it has to access is over there. So little but bashrc need to be done.
In terminal type: nano ~/.bashrc
Then add as
export PATH=$HOME/python/Python-2.7.6/:$PATH
and save -exit with CTRL+X+Y
then do
source ~/.bashrc
Recommended : restart your PC to update the new environment setting we've made.
That's it. Now on wards your system call python
from your home directory.
Related videos on Youtube
rugbert
Updated on September 18, 2022Comments
-
rugbert over 1 year
I need to install python so I can install pip/fab which do not need root access to run and install things. I'm setting up a vagrant VM environment which needs to run fab as non root to function and I really don't want to sudo everything or start changing permissions.
I know with OSX I can install python with brew which will install python to /usr/local/bin or something and then I can just edit my bash_profile path to look in that directoy first.
-
Wolverine over 9 yearsDo you need to install python without root permission?
-
muru over 9 years
pip
doesn't need root. Just dopip --user install ..
-
rugbert over 9 yearsI had to run pip with sudo in order to install fabric, and then my fab commands wouldnt work because it couldn't access certain folders without root perms
-
muru over 9 yearsYou don't have to, and you shouldn't have. It's not recommended.
-