Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install and use pip in a local directory without root/sudo access.

#Install and use pip in a local directory without root/sudo access. #####By: @saurabhshri

##Why? Many users when are given server access, do not have root (or sudo) privileges and can not simply do sudo apt-get install python-pip . Here's an easy way you can install and use pip without root (or sudo) access in a local directory. Note : This works without easy_install too.

##How?

  1. Download pip from an online repository : wget https://bootstrap.pypa.io/get-pip.py
  2. Install the downloaded package into a local directory : python get-pip.py --user This will install pip to your local directory (.local/bin).
  3. Now you may navigate to this directory (cd .local/bin) and then use pip or better set your $PATH variable this directory to use pip anywhere : PATH=$PATH:~/.local/bin followed by source ~/.bashrc to apply the changes.

And that's it. You may now install all python modules you require via pip in a local directory without root.

##Gist of Gist

wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py --user
cd .local/bin
./pip install <package_name> --user
@greggman

This comment has been minimized.

Copy link

greggman commented Nov 26, 2017

This came up as the first hit on Google for installing python packages as user but it's unfortunately mis-leading

This does not install in a local directory, it installs an OS specific user folder which is global for that user. It doesn't install in .local/bin in the current folder. It installs in ~/.local/bin (in your case). In my case it installs in ~/Library/Python/2.7/bin.

In either case that's not "my local directory" it's a effectively my "home directory" which is sadly not what I was looking for since I have various projects that need incompatible packages so needed actual solution for "local directory"

@emteeoh

This comment has been minimized.

Copy link

emteeoh commented Nov 29, 2017

@greggman you can, probably even should, be using virtualenv. You create one env per project, and then install packages to that env. --local will, AFAIK, still work too.

pip install virtualenv --user
cd project1_folder
source bin/activate
virtualenv project1
pip install db=1.0.0 --user

cd ../project2_folder
virtualenv project2
source bin/activate
pip install db=2.0.0 --user
@kenichi-shibata

This comment has been minimized.

Copy link

kenichi-shibata commented Dec 5, 2017

Fixed the formatting for you

Install and use pip in a local directory without root/sudo access.

By: @saurabhshri

Why?

Many users when are given server access, do not have root (or sudo) privileges and can not simply do sudo apt-get install python-pip . Here's an easy way you can install and use pip without root (or sudo) access in a local directory. Note : This works without easy_install too.

How?

Download pip from an online repository : wget https://bootstrap.pypa.io/get-pip.py
Install the downloaded package into a local directory : python get-pip.py --user This will install pip to your local directory (.local/bin).
Now you may navigate to this directory (cd .local/bin) and then use pip or better set your $PATH variable this directory to use pip anywhere : PATH=$PATH:~/.local/bin followed by source ~/.bashrc to apply the changes.
And that's it. You may now install all python modules you require via pip in a local directory without root.

Gist of Gist

wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py --user
cd .local/bin
./pip install <package_name> --user
@Moritz90

This comment has been minimized.

Copy link

Moritz90 commented Mar 28, 2018

@emteeoh @greggman
These days, you should probably be using pipenv instead of managing your virtualenv and your dependencies manually.

@texastony

This comment has been minimized.

Copy link

texastony commented Dec 24, 2018

@emteeoh @greggman
These days, you should probably be using pipenv instead of managing your virtualenv and your dependencies manually.

In March of 2018, I tried to use pipenv and ran into many issues with locking. I decided to come back to it later, after a few more releases. It worked great on my local and servers I was the admin for, but where I was just the user it struggled where virtualenv did not. @Moritz90, have you continued to have success in various environments with pipenv?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.