Last active
August 29, 2015 14:20
-
-
Save ivanalejandro0/d1ac4493892730a30d2b to your computer and use it in GitHub Desktop.
Environment variable tests using python c-api.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Python.h> | |
#include <iostream> | |
#include <cstdlib> | |
// compile with: | |
// g++ -o env env.cpp -O2 -Wall -Wno-long-long -pedantic -pthread $(pkg-config --cflags --libs python2) | |
void show_paths() { | |
std::string env_path; | |
env_path = std::getenv("PATH"); | |
if (env_path.c_str()) | |
std::cout << "PATH: " << env_path << std::endl; | |
else | |
std::cout << "PATH: NULL" << std::endl; | |
const char *search_path = Py_GetPath(); | |
if (search_path != NULL) { | |
// if there is a path to use append it to our custom search path as a fallback | |
std::cout << "Py_GetPath: " << search_path << std::endl; | |
} else { | |
std::cout << "Py_GetPath: NULL" << std::endl; | |
} | |
} | |
int main() | |
{ | |
std::cout << "Environment variables test" << std::endl << std::endl; | |
show_paths(); | |
} |
The important parts:
# env
Py_GetPath: /usr/lib/python2.7/:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload
# launcher
Py_GetPath: /usr/lib/python2.7/:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The odd thing is that
Py_GetPath
is returning different value depending on where is called from.