Friday, February 18, 2022

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

Issue

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?


Solution

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



Answered By - nfelger
Answer Checked By - Gilberto Lyons (WPSolving Admin)