Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: externally-managed-environment: This environment is externally managed #2201

Closed
robfantini opened this issue Jul 11, 2023 · 24 comments
Closed

Comments

@robfantini
Copy link

robfantini commented Jul 11, 2023

Describe the bug
All I have is the output from trying to start bazarr :

#  /opt/bazarr/bin/python3 /opt/bazarr/bazarr.py
Bazarr starting...
/usr/lib/python3/dist-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
2023-07-11 18:09:16,830 - root                             (7f905a2a02c0) :  INFO (init:88) - BAZARR installing requirements...
2023-07-11 18:09:17,087 - root                             (7f905a2a02c0) :  ERROR (init:97) - BAZARR requirements.txt installation result: b'error: externally-managed-environment\n\n\xc3\x97 This environment is externally managed\n\xe2\x95\xb0\xe2\x94\x80> To install Python packages system-wide, try apt install\n    python3-xyz, where xyz is the package you are trying to\n    install.\n    \n    If you wish to install a non-Debian-packaged Python package,\n    create a virtual environment using python3 -m venv path/to/venv.\n    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make\n    sure you have python3-full installed.\n    \n    If you wish to install a non-Debian packaged Python application,\n    it may be easiest to use pipx install xyz, which will manage a\n    virtual environment for you. Make sure you have pipx installed.\n    \n    See /usr/share/doc/python3.11/README.venv for more information.\n\nnote: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.\nhint: See PEP 668 for the detailed specification.\n'
Bazarr exited.

To Reproduce
Steps to reproduce the behavior:

  1. let bazarr uprade from 1.2.2 to 1.2.3
  2. start it up: /opt/bazarr/bin/python3 /opt/bazarr/bazarr.py

Software (please complete the following information):

  • Bazarr: 1.2.3

  • OS: Debian 12

Notes:
I checked the requirements.txt file for 1.2.2 and 1.2.3 and they are the same.

I have a test system set up and running in order to do any tests you may want .

Let me know if there is more info wanted or testing to try to fix.

thank you for this software.

Additional context
Add any other context about the problem here.

@morpheus65535
Copy link
Owner

@robfantini
Copy link
Author

robfantini commented Jul 12, 2023

I did have bazarr working before 1.2.3 . the system started as Debian 12 when I initially installed bazarr . at that point I had to do these


apt install python3-full mediainfo  
python3 -m venv /opt/bazarr/

```
`

also this is the systemd service.  note full path names

`
/etc/systemd/system/bazarr.service :
[Unit]
Description=Bazarr Daemon
#After=syslog.target network.target

After=network.target sonarr.service radarr.service

[Service]
WorkingDirectory=/opt/bazarr/
User=htuser
Group=user
UMask=0002
Restart=on-failure
RestartSec=5
Type=simple
ExecStart=/opt/bazarr/bin/python3 /opt/bazarr/bazarr.py
KillSignal=SIGINT
TimeoutStopSec=20
SyslogIdentifier=bazarr
ExecStartPre=/bin/sleep 30

[Install]
WantedBy=multi-user.target

`

@morpheus65535
Copy link
Owner

Bazarr 1.2.3 have a new requirement. It's been a long time since we added one so it's normal. Now, you operating system tell to Python to refuse to install requirements without using a venv. The other solution is to delete the file that instruct Python to refuse installation of requirements as instructed in the link I provided.

@robfantini
Copy link
Author

Okay I'll check the link and try to undo the venv stuff later on.

Also /opt/bazarr//requirements.txt on both systems is identical .
[ except on the new one I had edited it to remove an error and ended up with a line feed after Pillow>=9.0.0 . that should not make a difference ]
you mentioned there is a new requirement, should that be in the /opt/bazarr//requirements.txt file?

@morpheus65535
Copy link
Owner

In v1.2.3, requirements.txt looks like that: https://github.com/morpheus65535/bazarr/blob/master/requirements.txt

@robfantini
Copy link
Author

Okay I adjusted this line in requrements.txt , the rest were the same.
Pillow>=9.0.0 --only-binary=Pillow

still same error on startup using .

I can work on eliminating the venv setup in the evening or tomorrow. will need to research how to undo it...

@morpheus65535
Copy link
Owner

You don't need to eliminate the venv, you must use it or disable PEP-668 by deleting the EXTERNALLY-MANAGED marker file: https://peps.python.org/pep-0668/#marker-file

@morpheus65535
Copy link
Owner

Anything else to fix here?

@robfantini
Copy link
Author

Hello,
I just read https://peps.python.org/pep-0668/#marker-file again.

regarding:
'disable PEP-668 by deleting the EXTERNALLY-MANAGED marker file' - I could not find that file in the paths suggested by the link.
Could you give me some clues where the file may be and its' name?

@morpheus65535
Copy link
Owner

No news, good news!

@morpheus65535 morpheus65535 changed the title upgrade from 1.2.2 to 1.2.3 on Debian 12 caused bazarr to not be able to start error: externally-managed-environment: This environment is externally managed Oct 13, 2023
@morpheus65535 morpheus65535 pinned this issue Oct 13, 2023
@imthenachoman
Copy link

This is what I had to do on Debian 12.

$ sudo apt install python3-dev python3-pip python3-distutils unrar unzip
$ wget https://github.com/morpheus65535/bazarr/releases/latest/download/bazarr.zip
$ sudo mkdir /opt/bazarr
$ sudo unzip bazarr.zip -d /opt/bazarr
$ cd /opt/bazarr
$ python3 -m venv .venv
$ source .venv/bin/activate
$ python3 -m pip install -r requirements.txt
$ sudo chown -R $USER:$USER /opt/bazarr
$ sudo nano /etc/systemd/system/bazarr.service

/etc/systemd/system/bazarr.service (notice the path to python3 in the ExecStart command):

[Unit]
Description=Bazarr Daemon
After=syslog.target network.target

# After=syslog.target network.target sonarr.service radarr.service

[Service]
WorkingDirectory=/opt/bazarr/
User=media
Group=media
UMask=0002
Restart=on-failure
RestartSec=5
Type=simple
ExecStart=/opt/bazarr/.venv/bin/python3 /opt/bazarr/bazarr.py
KillSignal=SIGINT
TimeoutStopSec=20
SyslogIdentifier=bazarr
ExecStartPre=/bin/sleep 30

[Install]
WantedBy=multi-user.target
$ sudo systemctl start bazarr
$ sudo systemctl status bazarr
$ sudo systemctl enable bazarr

I hope this helps others.

References:

@ChristianMalazarte
Copy link

ChristianMalazarte commented Oct 25, 2023

For some reason, my .venv folder disappears when I restart the server and I have to recreate it again. Any clues as to why?

@imthenachoman
Copy link

Restart the bazarr app or your entire server? Where is your .venv folder? Super strange that it would be gone.

@ChristianMalazarte
Copy link

Restart the bazarr app or your entire server? Where is your .venv folder? Super strange that it would be gone.

Followed your instructions, so it's inside the /opt/bazarr/ folder. And restart computer not just the app.

@imthenachoman
Copy link

Try creating a file in /opt and /opt/bazarr and rebooting. Does it remove that file too? If so, then it must be something your OS is doing -- but I'm not sure why....

@bmorgan99
Copy link

@imthenachoman
This is what I had to do on Debian 12...

I did this very thing for sabnzbd a few days ago and it worked fine. I have tried and re-tried it for bazarr but keep getting [Errno 13] Permission denied when trying to satisfy the requirements. I'm not keen on disabling python's new safeguards, so I'll try to hold out for a fix.

@morpheus65535
Copy link
Owner

@bmorgan99 if you expect a fix on our side, you'll wait endlessly. There's nothing to fix on our side. The fix is disable the "safe guard" imposed by your operating system or use a venv.

@imthenachoman
Copy link

@morpheus65535 I'm not very familiar with all this but shouldn't Bazarr be updated to do what it needs to do to work with Python's safeguards?

@morpheus65535
Copy link
Owner

@imthenachoman I agree, you're not very familiar with this. This isn't a Python safeguard, it an operating system requested feature that Python decided to honour. Python doesn't need that, the user is responsible to make sure the requirements have been installed or that Bazarr is able to do it by itself (by running the same pip command a user would have done). Bazarr can't alter your operating system configuration by itself, you must allow it do what it need.

@imthenachoman
Copy link

@morpheus65535 Ah. So this is a Debian thing. Got it. Thank you.

Then, I think it would be nice/kind if the Bazaar instructions included help/steps on what the end-user needs to do to get Bazarr to work on OSes that have this setting set. I understand if that's not possible as developers are busy but I think it would be kind/helpful.

@morpheus65535
Copy link
Owner

@imthenachoman I agree, it would be nice and I'll happily accept a PR to the wiki page clarifying the required step.

@imthenachoman
Copy link

Cool. Hopefully someone is able to do that. I’m still not convinced what I did was the best approach. Thanks again!

@bmorgan99
Copy link

bmorgan99 commented Feb 2, 2024

For me, the fix was chown -R pi:pi /opt/bazarr for the install, then bazarr:bazarr after.
To run: /opt/bazarr/bazarr-venv/bin/python3 /opt/bazarr/bazarr.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants