0

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.

7
  • have you seen: stackoverflow.com/questions/51950533/… Commented Nov 27, 2023 at 16:22
  • I don't use Eclipse, but FWIW, this title doesn't sound very descriptive. Check out How to Ask for tips on that, plus more, like starting with your own research; e.g. do you understand what the error is saying? Have you tried googling it? Commented Nov 27, 2023 at 16:22
  • Thank you. Yes, I'v googled and read some posts about same error message. The problem is in that my python3 build works in PyDev and error appears in the child python process, spawned by the subprocess.call Commented Nov 27, 2023 at 16:29
  • 1
    Could your environment include path variables for one python, but the python3 command invoke a different python? I would try using an absolute path in your subprocess.call invocation to make sure you are running the python3 you think you are. Then I would check the environment to be sure it doesn't include any PYTHONPATH settings that point to a different python. Commented Nov 27, 2023 at 16:43
  • why import os when it is not used ? Commented Nov 27, 2023 at 19:02

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.