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
  Python use of virtual environments bre67e49 4 811 Feb-19-2025, 04:01 AM
Last Post: Sece1967
  MPEG DASH Package implementation similar to M3U8 package anantha_narayanan 0 609 Feb-06-2025, 03:55 AM
Last Post: anantha_narayanan
  I cannot create a virtual environment on visual studio code using python Willem_Aucamp316 2 3,607 Nov-27-2024, 02:20 PM
Last Post: menator01
  White Screen Issue with Toolbar After Python Installation evelynfreya 2 1,080 Nov-25-2024, 06:26 PM
Last Post: deanhystad
  Install a module to a specific to Python Installation (one of many)) tester_V 2 2,157 Oct-29-2024, 03:25 PM
Last Post: snippsat
  Shrink Python installation? Extract site-packages from .zip only on demand? pstein 4 1,658 Oct-28-2024, 04:29 PM
Last Post: snippsat
  How to enable Matplotlib within virtual environment? tetris_theMovie 1 1,122 Oct-11-2024, 09:56 AM
Last Post: christie2
  Troubleshooting Jupyter Notebook installation with Python using pip and a venv Drone4four 1 2,318 Jun-04-2024, 10:55 PM
Last Post: Drone4four
  Need help setting up trusted root ca in virtual environment dstempfley 0 1,260 May-31-2024, 03:14 PM
Last Post: dstempfley
  Help with creating folder and "virtual environment" AudunNilsen 1 1,029 Mar-21-2024, 04:41 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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