Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

virtualenv to use --system-site-packages, but only for specific packages?

In a perfect world, I'd like to use pip inside a --no-site-packages virtualenv.

However: OpenCV. From what I've read so far it sounds tricky to reliably install OpenCV in a virtualenv, so I've accepted having to install that as a system package for now (target platform is Ubuntu, so I'm installing python-opencv with apt). I'd like to install everything else with pip into my virtualenv, though.

To make OpenCV available to my application, I've initialized the virtualenv with --system-site-packages.

When installing other dependencies with env/bin/pip install -U -r requirements.txt now, some of the requirements (which happen to be dependencies of OpenCV) are seen as satisfied. Not surprising, but also not what I want.

Is there a sane way to make only OpenCV available from site-packages, and have everything thing else loaded from, and installed to, the virtualenv?

like image 747
nfelger Avatar asked Jan 26 '26 04:01

nfelger


1 Answers

In 2018, you can easily install recent versions of OpenCV in a virtualenv using the opencv-python package.

like image 52
nfelger Avatar answered Jan 27 '26 18:01

nfelger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!