Guest User

Untitled

a guest
Aug 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. cmake finds wrong python libs
  2. #include <Python.h>
  3. ...
  4. Py_Initialize();
  5. PyRun_SimpleFile(...);
  6. Py_Finalize();
  7.  
  8. FIND_PACKAGE(PythonLibs REQUIRED)
  9. ...
  10. TARGET_LINK_LIBRARIES(MyApplication ${PYTHON_LIBRARIES})
  11.  
  12. try:
  13. import some_package
  14. except ImportError:
  15. if "my_python_path" in sys.path: raise
  16. sys.path.append("my_python_path")
  17.  
  18. cmake -DPYTHON_LIBRARIES=/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib .
  19.  
  20. ccmake .
  21.  
  22. /* Search in some common locations for the associated Python libraries.
  23. *
  24. * Two directories must be found, the platform independent directory
  25. * (prefix), containing the common .py and .pyc files, and the platform
  26. * dependent directory (exec_prefix), containing the shared library
  27. * modules. Note that prefix and exec_prefix can be the same directory,
  28. * but for some installations, they are different.
  29. *
  30. * Py_GetPath() carries out separate searches for prefix and exec_prefix.
  31. * Each search tries a number of different locations until a ``landmark''
  32. * file or directory is found. If no prefix or exec_prefix is found, a
  33. * warning message is issued and the preprocessor defined PREFIX and
  34. * EXEC_PREFIX are used (even though they will not work); python carries on
  35. * as best as is possible, but most imports will fail.
  36. *
  37. * Before any searches are done, the location of the executable is
  38. * determined. If argv[0] has one or more slashes in it, it is used
  39. * unchanged. Otherwise, it must have been invoked from the shell's path,
  40. * so we search $PATH for the named executable and use that. If the
  41. * executable was not found on $PATH (or there was no $PATH environment
  42. * variable), the original argv[0] string is used.
  43. *
  44. * Next, the executable location is examined to see if it is a symbolic
  45. * link. If so, the link is chased (correctly interpreting a relative
  46. * pathname if one is found) and the directory of the link target is used.
  47. *
  48. * Finally, argv0_path is set to the directory containing the executable
  49. * (i.e. the last component is stripped).
  50. *
  51. * With argv0_path in hand, we perform a number of steps. The same steps
  52. * are performed for prefix and for exec_prefix, but with a different
  53. * landmark.
  54. *
  55. * Step 1. Are we running python out of the build directory? This is
  56. * checked by looking for a different kind of landmark relative to
  57. * argv0_path. For prefix, the landmark's path is derived from the VPATH
  58. * preprocessor variable (taking into account that its value is almost, but
  59. * not quite, what we need). For exec_prefix, the landmark is
  60. * Modules/Setup. If the landmark is found, we're done.
  61. *
  62. * For the remaining steps, the prefix landmark will always be
  63. * lib/python$VERSION/os.py and the exec_prefix will always be
  64. * lib/python$VERSION/lib-dynload, where $VERSION is Python's version
  65. * number as supplied by the Makefile. Note that this means that no more
  66. * build directory checking is performed; if the first step did not find
  67. * the landmarks, the assumption is that python is running from an
  68. * installed setup.
  69. *
  70. * Step 2. See if the $PYTHONHOME environment variable points to the
  71. * installed location of the Python libraries. If $PYTHONHOME is set, then
  72. * it points to prefix and exec_prefix. $PYTHONHOME can be a single
  73. * directory, which is used for both, or the prefix and exec_prefix
  74. * directories separated by a colon.
  75. *
  76. * Step 3. Try to find prefix and exec_prefix relative to argv0_path,
  77. * backtracking up the path until it is exhausted. This is the most common
  78. * step to succeed. Note that if prefix and exec_prefix are different,
  79. * exec_prefix is more likely to be found; however if exec_prefix is a
  80. * subdirectory of prefix, both will be found.
  81. *
  82. * Step 4. Search the directories pointed to by the preprocessor variables
  83. * PREFIX and EXEC_PREFIX. These are supplied by the Makefile but can be
  84. * passed in as options to the configure script.
  85. *
  86. * That's it!
  87. *
  88. * Well, almost. Once we have determined prefix and exec_prefix, the
  89. * preprocessor variable PYTHONPATH is used to construct a path. Each
  90. * relative path on PYTHONPATH is prefixed with prefix. Then the directory
  91. * containing the shared library modules is appended. The environment
  92. * variable $PYTHONPATH is inserted in front of it all. Finally, the
  93. * prefix and exec_prefix globals are tweaked so they reflect the values
  94. * expected by other code, by stripping the "lib/python$VERSION/..." stuff
  95. * off. If either points to the build directory, the globals are reset to
  96. * the corresponding preprocessor variables (so sys.prefix will reflect the
  97. * installation location, even though sys.path points into the build
  98. * directory). This seems to make more sense given that currently the only
  99. * known use of sys.prefix and sys.exec_prefix is for the ILU installation
  100. * process to find the installed Python tree.
  101. */
Add Comment
Please, Sign In to add comment