Python script on Debian 12?

Sonarr version (exact version): 3.0.10.1567
Mono version (if Sonarr is not running on Windows): 6.12.0.182
OS: Debian 12
Debug logs: None
Description of issue:
I’ve just moved to a new server that has Debian 12 on it.
With Debian 12, Python now requires modules to be installed and run from virtual environments.
You can’t just pip install globally or at the user level anymore. You have to create a virtual environment, source/activate it and then you can install your modules. Your scripts need to be run via the venv though.
That is causing me trouble because Sonarr doesn’t run via any Python venv and I’m not sure how to do it.

To run any Python script on Debian 12:

  • Create a venv: python3 -m venv ~/my-sonarr-venv
  • Active the venv: source ~/my-sonarr-venv/bin/activate
  • Install your modules: python3 -m pip install requests python-dotenv etc...
  • Run your script: python3 your_scripts.py

A bit of a pain not to say the least, but it’s part of PEP 668.
That’s how I understand the new system works.

Anybody in the same boat or have any insight on how to run custom python scripts with a virtual environment enabled?
Or maybe there’s a way to have Python behave the old fashion way and not requiring a venv?

Never mind, looks like a lot of modules are actually available through Debian’s packet manager.
They’re available by pre-pending “python3-” to your module name. The module name in your distro’s packet manager might be different, you’ll have to figure it out. Sometimes a module name doesn’t match its package name.
For example, the “dotenv” module is usually installed with a package name of “python-dotenv” when using pip. The “requests” module on the other hand, has the same module name as its package name.
In my case, I only needed the “requests” and “dotenv” modules, so:
sudo apt install python3-requests python3-dotenv

If the modules you need don’t happen to be in your distro’s packet manager, you can still install them by parsing the “–break-system-packages” option to your pip command, but it’s really not recommended:
pip install requests python-dotenv --break-system-packages

I’m lucky enough to have root access so I can use Debian’s packet manager, but for folks without root, not sure how this can be achieved other than using a virtual environment or the “–break-system-packages” option =/
But yeah, the way they’re pushing things is to use a virtual environment, which has pros and cons, but this ain’t the topic.

Have a great day :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.