How do python virtual environments handle site packages?

Following on from

I now have a virtual environment in which to run the python module in 3.11.

But the python module appears to be missing some dependencies (tsk!), in this case pyqt.

I could pip install pyqt in the virtual environment, but a) I don’t like pip installing more than I absolutely have to, and b) it’s reasonable to assume there’ll be more hidden dependencies.

So I’m thinking of allowing site system packages by setting pyvenv.cfg to site-system-packages=true

My question is, what will happen now the virtual environment will, as a result, have access to newer versions of many of the packages installed as dependencies?

And, a supplementary question, can the installed module running in the virtual environment now start messing with my system packages? (Thus rendering the whole virtual environment pointless)

The site-system packages are v3.13, in my example, I had to install pysimplegui with pip to get the script to run, otherwise it would not run.

What exactly are you trying to run?

I’m trying to run a module called opensesame https://pypi.org/project/opensesame-core/
I’ve actually managed to find online someone saying it’s pyqt5 it needs, so I installed that in the virtual environment and it now opens…

…of course, it doesn’t actually work… that would be too much to ask

It’s now complaining about the lack of PyQtWebEngine…

… and pygame…

… and … goodness knows what else to come.

If this wasn’t for work, I’d have given up at this stage, but here we are. I suppose it’s just going to be a matter of installing everything it’s lacking one pip install at a time so hopefully I’ll dodge https://thehackernews.com/2023/12/116-malware-packages-found-on-pypi.html

Just curious, are you new to python development or coding?

If you are installing multiple dependencies for a project/package, it is usually put in a requirements.txt with correct version numbers. If you directly install from pip, you might install the wrong verisons.

god knows how, but I seem to have it working, I need to check my command history BRB. (This was under bash, fish didn’t like it).

## Bash & Fish:
pip install opensesame-core
pip install pyqt5
## Then (Bash):
export QT_QPA_PLATFORM=xcb
bin/opensesamerun
## Fish:
set QT_QPA_PLATFORM xcb
echo $QT_QPA_PLATFORM # should say xcb
bin/opensesamerun

all the above in the venv

1 Like

Just thinking about this - the “easiest” solution is to run an Ubuntu/Mint/Debian virtual machine…

2 Likes

I certainly would be if I were either developing or coding. But I’m neither. I was told by work I needed to use this software, it comes with installation instructions for Windows and Mac, but I have neither. Hence, I’m here.

There’s no requirements.txt that I can find.

The thought crossed my mind…

I have, however, got it running. It was an odd fix, but it needed a specially built version of expyriment (see what what they did there… expyriment… classic). Something about SLD versions being incompatible with two of the packages…

Anyway. All working.

2 Likes

:clap: nice to hear