How to use pip3 without sudo privileges

In my case, there are several python3.x version installed in my system before, and I had to type python3.x and sudo pip3 for developing the code every time, which disturbed me. 

Here are the methods I tried to solve this problem. Now I am able to type only the python3 command for the newest python3.8 use and pip3 for installing modules without root privileges.

  • python3.x ... -> python3 ...
  • sudo pip3.x install ... -> pip3 install / python3 -m pip install ... 


1. Install pip3 locally under /home/$USER/.local/bin/.

$ wget https://bootstrap.pypa.io/get-pip.py

$ python3 get-pip.py --user

2. Edit ~/.bashrc

$ export PATH=$PATH:~/.local/bin

$ export PYTHONPATH=$PYTHONPATH:/usr/lib/python3.8/dist-packages

$ source ~/.bashrc

3. Delete redundant pip path or error: ModuleNotFoundError: No module named 'pip._vendor.retrying' will be reported.

$ sudo rm -r /usr/lib/python3/dist-packages/pip


Check:

$ python3 --version


* Difference between /usr/local and /usr/.local

/usr/local is a place where software usable by all users can be installed by an administrator.
~/.local/bin is a place where a user can install software for their own use.


留言

這個網誌中的熱門文章

Tuing PID parameters in QGroundcontrol (2)

Useful PX4 Parameters

Burn linux image to eMMC storage on Banana Pi M3