in Education by
I'm trying to embed python into a C application. For the moment, I am trying to get the following hello world style example working #include <..../anaconda3/include/python3.7m/Python.h> // I've abbreviated this path for privacy int main() { Py_Initialize(); PyRun_SimpleString("from time import time,ctime\nprint('Today is', ctime(time()))\n"); Py_FinalizeEx(); return(EXIT_SUCCESS); } I've been able to compile this example but I get the following error when I run it Could not find platform independent libraries Could not find platform dependent libraries Consider setting $PYTHONHOME to [:] Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named 'encodings' I have multiple versions of python installed (python3, I'm using macOS) and want to run a specific anaconda version that I have installed. As I understand the above problem, the reason I am getting this error is because I need to give a the specific path for python to look for libraries/modules. Setting PYTHONHOME and/or PYTHONPATH should fix this problem then. However, I'm not sure what I should set this value to. My question is two fold. (1) Have I correctly diagnosed the problem? (2) If so, what should I set these two environment variables to? Specifically, what are the specific paths? While there have been several other posts regarding this problem none seem to give the what the paths should be (I've tried setting just the PYTHONHOME variable to "..../anaconda" since one of the answers in this post stated that it should be set to the parent folder of the bin file of python which in this case is anaconda. Doing this did not fix the problem.). Edit: Applying the changes suggested by @John Bollinger seems to partially solve the problem. The resulting error is now Fatal Python error: initfsencoding: unable to load the file system codec ModuleNotFoundError: No module named 'encodings' JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
As I understand the above problem, the reason I am getting this error is because I need to give a the specific path for python to look for libraries/modules. Setting PYTHONHOME and/or PYTHONPATH should fix this problem then. [...] Have I correctly diagnosed the problem? It sounds like it. The Python interpreter chooses the default module path based either on PYTHONHOME or on its installation location and compile-time configuration, but the latter is out the window when you embed the interpreter in another program. The interpreter uses PYTHONPATH to identify additional directories to search for modules. You should not normally set PYTHONHOME when using the standalone interpreter, but it is reasonable to do so when embedding the interpreter. If so, what should I set these two environment variables to? The output of python3 -h on my system includes this: PYTHONPATH : ':'-separated list of directories prefixed to the default module search path. The result is sys.path. PYTHONHOME : alternate directory (or :). The default module search path uses /pythonX.X. Note in particular the hint about what Python expects to find in a directory named by PYTHONHOME. In your case, you should probably set PYTHONHOME because the interpreter does not recognize how to find the system modules. The actual value that variable should take depends on where the desired Python implementation resides (and this should probably be the same implementation whose python library you linked your program against). For the system Python, on my machine, it would be PYTHONHOME=/usr/lib:/usr/lib64 For my Anaconda 2, installed in /opt/anaconda2, it would be PYTHONHOME=/opt/anaconda2/lib You should not need to set PYTHONPATH (and, in fact, you might want to ensure it is unset) unless there are additional locations you want Python to search for modules.

Related questions

0 votes
    Background: I'm trying to look through assets in an old game's archive files. They're 8-bit. I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I have a function in c++ that receives a initialised class as a PyObject. The python class is: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I have a function in c++ that receives a initialised class as a PyObject. The python class is: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 22, 2022 in Education by JackTerrance
0 votes
    I'm pretty new at laravel, in fact and I'm trying to create my very first project. for some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I've been trying to get my discord bot to work, but it will only become online on discord and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
0 votes
    Designing a registration form, and I get this error when adding in MessageBoxButtons and MessageBoxIcon. The error ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am currently following along with a somewhat questionable Django tutorial called A complete blog engine using ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have a single protobuf which generates out C# and Go code. The protobuf contains: syntax = "proto3" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Which platform could gain its best use case from financial service industry? A. Hyperledger B. R3 Corda C. Ethereum D. All the options...
asked Nov 30, 2022 in Education by JackTerrance
0 votes
    Is Python platform independent? 1. Yes 2. No...
asked Nov 26, 2020 in Technology by JackTerrance
0 votes
    Is SOAP platform independent?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    Given two independent events A and B such that P (A) = 0.3, P (B) = 0.6. Find (i) P (A and B) (ii) P ( ... B) (iv) P (neither A nor B) Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
...