I am trying to call a python function from a C program but when trying to run the compiled program I get the error:
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007fff94214380 (most recent call first):
Abort trap: 6
I am using python3.7 installed using anaconda3 on macOS High Sierra 10.13.5.
To compile my code called callpy.c, I used
gcc -o callpy callpy.c -I/Users/wernop/anaconda3/include/python3.7m -L/Users/wernop/anaconda3/lib/python3.7/config-3.7m-darwin -lpython3.7m
which runs without errors or warnings.
I saw this question: Fatal Python error: initfsencoding: unable to load the file system codec and therefore made sure to set the environmnent variables
PYTHONPATH='/Users/wernop/anaconda3/bin/python3.7'
PYTHONHOME='/Users/wernop/anaconda3/bin/python3.7'
I would be grateful for any help.
/Users/wernop/anaconda3. Should my environment variables be set differently?PYTHONPATH='/Users/wernop/anaconda3/bin/python3.7'doesn't do what you expect.PYTHONPATHshould point to library roots, not executables. Run the following:python3.7 -c "import encodings; print(encodings.__file__). Make sure you use the right executable from anaconda installation. This should print you a path like/usr/lib64/python3.7/encodings/__init__.py. You thus setPYTHONPATH="/usr/lib64/python3.7". Print the contents ofsys.pathin your code to see whetherPYTHONPATHwas applied correctly.python3-config --cflags --ldflags.