Skip to content

Instantly share code, notes, and snippets.

@ivanalejandro0
Last active August 29, 2015 14:20
Show Gist options
  • Save ivanalejandro0/d1ac4493892730a30d2b to your computer and use it in GitHub Desktop.
Save ivanalejandro0/d1ac4493892730a30d2b to your computer and use it in GitHub Desktop.
Environment variable tests using python c-api.
#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();
}
@ivanalejandro0
Copy link
Author

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