Search code examples
pythonlinuxubuntupip

Best way to Install Pip packages(Ubuntu/Linux)


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.


Solution

  • 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.