Python Forum
Which package installation methods to use inside a python virtual environment?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Which package installation methods to use inside a python virtual environment?
#1
I am using virtualenv. I know that using pip install <package_name> inside a python virtual environment will isolate that package (the package is only to be found inside the virtual environment). What about installing a package inside a python virtual environment using these methods: sudo pip install, sudo apt-get install, or building the package from source? Will they isolate the package? is the package going to be installed on the whole system?
Reply
#2
You only use sudo or elevated permissions when you want to install stuff for the global, system-wide Python installation.
A bonus is that virtualenv does not need elevated permissions.

It's best to always try to avoid sudo pip install,also for pip usage on OS without virtualenv.
Instead, consider using pip install --user,or pyenv as i use.
With pyenv OS installation so is Python always in user mode and never need for sudo pip install.
edwinksl Wrote:When you run pip with sudo, you run setup.py with sudo.
In other words, you run arbitrary Python code from the Internet as root.
If someone puts up a malicious project on PyPI and you install it, you give an attacker root access to your machine.
Prior to some recent fixes to pip and PyPI, n attacker could also run a man in the middle attack to inject their code when you download a trustworthy project.
Reply
#3
I also use -n <env name> to make sure that it is only installed in that env.
Some will say you don't need to do that, but I feel why not be safe.
Gary
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with creating folder and "virtual environment" AudunNilsen 1 171 Mar-21-2024, 04:41 AM
Last Post: deanhystad
  Best practice on using virtual environments in Python bytecrunch 6 638 Feb-14-2024, 03:22 PM
Last Post: snippsat
  How to run utilities from a Python package? LugosisGhost 1 388 Dec-27-2023, 12:00 PM
Last Post: Larz60+
  Virtual Env changing mysql connection string in python Fredesetes 0 320 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  Python installation for old MacOS Yonix 1 456 Sep-21-2023, 03:32 PM
Last Post: menator01
  Installing python packages in a virtual environment Led_Zeppelin 1 711 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Installation of packages to newest Python version from previous one Andrzej_Andrzej 3 779 Jul-15-2023, 11:32 AM
Last Post: snippsat
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,155 May-10-2023, 02:13 PM
Last Post: Calab
  Python development environment standenman 3 1,521 May-04-2023, 07:24 PM
Last Post: snippsat
  How to see the date of installation of python modules. newbieAuggie2019 4 1,461 Mar-31-2023, 12:40 PM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020