1

I'm wondering if there is a standard way to install python applications with pip (without using sudo) to get it to work globally?

Example:

  • I want to install a command line journal application with pip called jrnl. It works fine if you do "sudo pip install jrnl", however, I'm guessing this is a cringe-worthy way to do it.

  • If I install without sudo just using "pip install jrnl" it installs in .local/ without global access.

I've found several ways to do it but wondering if there is a common and accepted way to do it that is secure?

Thanks!

1
  • Add that location to your path! Jun 24, 2018 at 11:56

1 Answer 1

1

It can be installed anywhere that is in your path. Several options I found are:

  1. Install to .local via:

    • pip install --user <pip-pkg-name>
    • This will install it in .local as you have noted so that location needs to be in your path, using the .bashrc file that can be done.
    • Add this export PATH=$PATH:/home/$USER/.local/bin to your /home/$USER/.bashrc file. With that you can reach it from anywhere.
  2. Add a custom path for with this line export PYTHONUSERBASE=/myappenv in your .bashrc file. Now when you do pip install --user <pip-pkg-name> it will be installed in /myappenv.

    • Note you have to create that path /myappenv first and add it to your .bashrc file with the line export PATH=$PATH:/myappenv
  3. Now that being said the so-called standard way you mentioned should be using python environment a.ka. virtualenv to install and run packages for that app and not globally as done in (1) and (2) above.

    • Install either for python2+ with sudo pip install virtualenv, or for python 3+ with sudo pip3 install virtualenv.
    • Usage:

      • virtualenv venv
      • Pick an interpreter of your choice with:

        • Python 2+: virtualenv -p python2.7 venv
        • Python 3+: virtualenv -p python3 myenv
      • Activate it: source venv/bin/activate
      • Deactivate it: deactivate

See:

http://kazhack.org/?post/2014/12/12/pip-gem-install-without-sudo,

https://gist.github.com/Geoyi/d9fab4f609e9f75941946be45000632b

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .