How to install pip (python) to user without root access

65,822

Solution 1

I hope I'm right and the problem is with your PATH, try this

You can add this to your ~/.bashrc file:

PATH=$PATH:~/.local/bin

If you don't know how, you can just execute this line in a Terminal:

echo "PATH=\$PATH:~/.local/bin" >> ~/.bashrc

You can also check what's in your PATH by typing in the Terminal

echo $PATH

Solution 2

This may be related. How to install python from source on a remote machine without root access.

Installing Python 3.6 (works with any version per say)

  1. Get the official download link from python.org website (example)

  2. Download the python source release and get the folder readied for installation from source.

    wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
    tar zxfv Python-3.6.9.tgz
    find ~/inflated_location/Python-3.6.9/Python -type d | xargs chmod 0755
    cd Python-3.6.9
    
  3. Install from source

    ./configure --prefix=~/inflated_location/Python-3.6.9/Python
    make
    make install
    
  4. Export the path variable

    nano ~/.bashrc
    export PATH=~/inflated_folder/python/Python-3.6.9/:$PATH
    source ~/.bashrc
    

Now you have python3.6 installed for logged in user and can be invoked now using command python

Installing py packages

The easiest way that I have followed is

python -m pip install <package-name> --user

Reference

Share:
65,822

Related videos on Youtube

Lucidnonsense
Author by

Lucidnonsense

Updated on September 18, 2022

Comments

  • Lucidnonsense
    Lucidnonsense over 1 year

    I'm trying to install pip (python installer) to my username since I don't have root privileges and can't just sudo apt-get install python-pip.

    So what I've done is just easy_install --user pip. That installs it to .local/bin apparently but then when I call it like so:

    pip install --user astropy

    It says that pip is not currently installed.

    I have limited knowledge of linux and of the system I'm using (NX connection to a machine at my university). I know I should be able to do this!

    • Admin
      Admin over 9 years
      If easy_install is not available, you can install pip to local with wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py && python get-pip.py --user
    • Admin
      Admin over 7 years
      Here is the up-to-date version of the above method: wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py --user
    • Admin
      Admin over 7 years
      Get this error: OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip'
    • Admin
      Admin over 7 years
      @ablmf - did you add the --user when running python get-pip.py --user ?
    • Admin
      Admin almost 7 years
      @qed 's comment should be the accepted answer
    • Admin
      Admin about 6 years
      If you have no wget: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  • JorgeGT
    JorgeGT over 9 years
    Don't forget to source ~/.bashrc for the change to make effect!