skip to Main Content

I was wondering since there are so many optinos to install a python package which one is be best and most convenient. should I install packages with sudo and pip3 commands,
E.g

sudo pip3 install <package>

only using pip3
E.g

pip3 install <package>

or using apt

sudo apt install <python-package>

I was wondering which is the go-to and will be most convenient in the future. Mostly wondering what is the difference between Sudo pip3 and pip3 what difference does it make and which one I should use.

2

Answers


  1. Don’t use sudo with pip. There is a chance you’ll overwrite system-installed packages, and mess up your OS.

    sudo apt install <python-package> is pretty safe, but may result in outdated packages, and will definitely not include all packages you may want to install.

    pip3 install <package> will install packages for just the current user (thus, not system-wide; if you’re the only user, you’re fine), and is what I would recommend.

    Going further, virtual environment or use of Conda (an "extended" virtual environment manager) are potentially even safer, at the cost of a little more work to set up, and a bit more disk space (usually, the latter is insignificant).

    You will have to read up on the use of virtual environment or Conda. That topic is too long for a standard answer here.

    Login or Signup to reply.
  2. I would suggest as first step reading package documentation, as it often contains information regarding how to install it. Few examples regarding popular packages

    • click suggests pip install click
    • jinja2 suggests pip install Jinja2
    • requests suggests python -m pip install requests

    Before that check to what version pertains python in your machine (by checking output of python --version), if it is Python 2 and you want to install packages to Python 3, then you need to use pip3 and python3 rather than pip and python, if it is Python 3 you might use command as they are.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search