KxSystems / embedPy

Allows the kdb+ interpreter to call Python functions
https://code.kx.com/q/interfaces
Apache License 2.0
89 stars 42 forks source link

ModuleNotFoundError when using embedPy with the venv module #43

Closed simon-graham closed 4 years ago

simon-graham commented 6 years ago

Using with system Python works fine:

$ echo 'p)print(2+2)' | q
4

However, if I try to do the same in an empty virtual environment I get an error:

python3.6 -m venv env
source env/bin/activate
(env) $ echo 'p)print(2+2)' | q
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007f887ee51000 (most recent call first):
Aborted

A similar issue was reported here: https://bugs.python.org/issue22213

The conclusion was this workaround which uses Py_SetPythonHome for virtualenv and Py_SetProgramName for venv:

https://github.com/GrahamDumpleton/mod_wsgi/blob/a4ddd9fd9f8fcc60d5da267d8c510d1759cf7b59/src/server/wsgi_interp.c#L2282-L2316