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.