![]() |
#1 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 442
Karma: 2666666
Join Date: Nov 2020
Device: none
|
Python can't find standard library in subprocess on Fedora
A user reported this error: https://github.com/xxyzz/WordDumb/issues/54
I'm able to fix the error by setting `PYTHONHOME` in `subprocess.run()`'s `env` parameter but I want to know why this error only occurs on Fedora. Last edited by xxyzz; 07-30-2022 at 03:36 AM. |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,364
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
presumably because fedora just moved to python 3.10
|
![]() |
![]() |
![]() |
#3 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 442
Karma: 2666666
Join Date: Nov 2020
Device: none
|
But the same code runs fine on Fedora's python.
Code:
import subprocess r = subprocess.run(["python3", "-m", "pip", "--version"], check=True, text=True, capture_output=True) `r.stderr`: Code:
Could not find platform independent libraries <prefix>\n Could not find platform dependent libraries <exec_prefix>\n Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n Python path configuration:\n PYTHONHOME = (not set)\n PYTHONPATH = (not set)\n program name = 'python3'\n isolated = 0\n environment = 1\n user site = 1\n import site = 1\n sys._base_executable = '/usr/bin/python3'\n sys.base_prefix = '/tmp/t/python-n51y8gtd'\n sys.base_exec_prefix = '/tmp/t/python-n51y8gtd'\n sys.platlibdir = 'lib'\n sys.executable = '/usr/bin/python3'\n sys.prefix = '/tmp/t/python-n51y8gtd'\n sys.exec_prefix = '/tmp/t/python-n51y8gtd'\n sys.path = [\n '/tmp/t/python-n51y8gtd/lib/python310.zip',\n '/tmp/t/python-n51y8gtd/lib/python3.10',\n '/tmp/t/python-n51y8gtd/lib/lib-dynload',\n ]\n Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding\n Python runtime state: core initialized\n ModuleNotFoundError: No module named 'encodings'\n\n Current thread 0x00007f824f149740 (most recent call first):\n <no Python frame>\n" Last edited by xxyzz; 07-30-2022 at 03:23 AM. |
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,364
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You would need to ask whoever maintains the fedora calibre package or tell your user to use the official binary.
|
![]() |
![]() |
![]() |
#5 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 442
Karma: 2666666
Join Date: Nov 2020
Device: none
|
I forget to mention this is the official calibre binary, Fedora 36's package is still calibre 5.
Last edited by xxyzz; 07-29-2022 at 10:36 PM. |
![]() |
![]() |
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,364
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The tracebackk in your bug report includes lines from the system pythons subprocess module. The only way that can happen is if you added the system python's path to sys.path, since calibre has its own python. Dont do that.
|
![]() |
![]() |
![]() |
#7 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 442
Karma: 2666666
Join Date: Nov 2020
Device: none
|
No I didn't add anything to `sys.path`...
That one line of code(`subprocess.run(["python3", "-m", "pip", "--version"], text=True, capture_output=True)`) alone will get this error. Last edited by xxyzz; 07-30-2022 at 03:22 AM. |
![]() |
![]() |
![]() |
#8 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,364
Karma: 27230406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
aaah you are running external python3 as a subprocess. You need to use the sanitize_env_vars() context manager in that case.
|
![]() |
![]() |
![]() |
#9 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 442
Karma: 2666666
Join Date: Nov 2020
Device: none
|
Thank you so much!
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
subprocess.Popen get FileNotFoundError but works fine in debug mode | xxyzz | Development | 2 | 01-01-2021 08:50 PM |
Find Non Standard Conversion Settings | BetterRed | Conversion | 4 | 07-04-2013 10:13 AM |
Using Calibre as a Python Library | dwyera | Development | 1 | 07-30-2012 07:17 AM |
Standard apps (games) pocketbook 302, where to find? | Saille | PocketBook | 13 | 07-06-2010 11:45 AM |
Is there a standard format for library eBooks? | RonaldJJames | General Discussions | 16 | 03-15-2010 01:59 PM |