1

I have a python 3 script that I am invoking from another Python 2.7.x script, using subprocess.popen.

myproc = subprocess.Popen(
         "/path/to/my/python/3/script",
          stdout=subprocess.PIPE,
          stderr=subprocess.PIPE,
          cwd=mypwd,
          shell=True)

When I debug this script using Eclipse and print out stderr I see the following issue:

Fatal Python error: Py_Initialize: Unable to get the locale encoding

The issue is NOT seen when I execute the same code in a script outside Eclipse.

Any help to solve this will be greatly appreciated!

1

1 Answer 1

1

Same problem with subprocess.check_call

I've solved mine passing env

subprocess.check_call(cmd,env={'PATH': '/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games',
                                       'LANG': 'it_IT.UTF-8',
                                       })

I think pydev changes environment to do some magic. Not sure both PATH and LANG needed.

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

1 Comment

Tested and confirmed that this is a PyDev issue. I started my script from the terminal and no problems at all. However instead of doing what you are doing I would suggest trying to find the properties in PyDev (general settings or the specific project) instead of passing fixed values. The problem with your solution is that the moment the path and/or the LANG have different values (though valid ones for the rest of the operating system) your solution will fail.

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.