Running simple test python3 script in eclipse/pydev Debian 11:
import subprocess
import os
subprocess.call(["python3", "-c", "print(123)"])
causes following error:
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
Traceback (most recent call last):
File "/opt/python/3/3.11/lib/python3.11/io.py", line 54, in <module>
ImportError: cannot import name 'text_encoding' from 'io' (unknown location)
Running that script in a console works fine. I use python3, built from sources and installed in opt, and virtual environment, also in opt. System version of python runs the code in pydev, custom python works only in console.
Eclipse pydev was setup to use 2 versons of python: system 3.9 and custom 3.11 in opt. My complex PyQT project runs fine in pydev using both versions of python, so my python3 built and virtual env look functional except subprocess, running python3 command.
Added: Error message comes from the child python process. The code outside the subprocess.call works.
Solved.
The problem comes from mismatch between environmental variables PATH and PYTHONPATH.
When we add custom python installation to the PyDev interpreters list, and later use that interpreter in PyDev python project, the run configuration has PYTHONPATH variable, which points to the python setup directories of libs and modules of the used interpreter. But the PATH variable stay unchanged, because interpreter will be started by the eclipse using absolute path, as it looks like. When we start child process with subprocess.call using "python3 ..." command line, then system python3 is spawned using non-system PYTHONPATH value.
The solution is to add PATH variable to your projects run configuration which points to the custom python installation bin catalogue or use absolute path to the python in subprocess.call.