2

I want to use a static python interpreter to run on a rigidly managed server. So far I've built the interpreter, but I can only use it within the build directory.

If I try to copy it and use the copy, it stops working, and fails with the following error-

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000002812900 (most recent call first):
zsh: abort (core dumped)  ./../python

I have seen this question, and using the fix suggested in the first answer gets rid of the prefix and exec_prefix problems, but not the 'Unable to get the locale encoding' problem. I can't really find a solution for this relevant to me.

This has nothing to do with virtualenv by the way, echo $PYTHONPATH and echo $PYTHONHOME both return an empty string when I try it outside of any virtualenvs. I can run the static binary just fine when it is in the build directory.

Here's an example of this-

~/Python-3.7.2$ ./python
Python 3.7.2 (default, Jan 26 2019, 19:14:39) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
~/Python-3.7.2$ cp python ..
~/Python-3.7.2$ ./../python 
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000000002812900 (most recent call first):
zsh: abort (core dumped)  ./../python

~/Python-3.7.2$ export PYTHONHOME=/usr/local
~/Python-3.7.2$ ./../python                 
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000000011b1900 (most recent call first):
zsh: abort (core dumped)  ./../python

Warpspeed SCP
  • 154
  • 2
  • 17

1 Answers1

0

Ok, I've solved my problem. This is caused by setting the --prefix option in configure. When you don't specify the correct prefix when running it, python won't know where its standard library is.

To use the python binary from wherever you want, you should manually specify the PYTHONHOME and PYTHONPATH environment variables, or keep the binary in the directory specified when you ran configure.

For example, if you ran configure with --prefix=/home/blah/python_src then you must keep the binary you build there or do something like export PYTHONHOME=/home/blah/python_src before using it.

Warpspeed SCP
  • 154
  • 2
  • 17