This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add Py_SetPath API for embedding python
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.2
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: kristjan.jonsson, pitrou
Priority: normal Keywords: easy, needs review, patch

Created on 2010-09-21 06:32 by kristjan.jonsson, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
py_setpath.patch kristjan.jonsson, 2010-09-21 06:32
py_setpath.patch kristjan.jonsson, 2010-09-25 03:03
Messages (6)
msg117030 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-09-21 06:32
When calling Py_Initialize() from an embedding application, there is currently no way for the application to override Python's initial settin g of sys.path.  An elaborate mechanism in getpathp.c kicks in, guessing the path based on several criteria.

Ideally, this mechanism, which is valid only for python.exe and its semantics, should be opt in.  It forces embedders that have their own libraries to go through complicated hoops (with environment variables and what not) to direct their embedded interpreter at the right place for modules, and to make sure that it is not confused by any other python distribution present on the system.

This submission adds a Py_SetPath() function to the API.  This has been successfully used by CCP in EVE Online and other products to completely override python's path guessing mechanics.  If called with a semicolon separated path prior to Py_Initialize, it will be used as the fodder for the initial sys.path.
msg117041 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-21 09:18
You must also update Modules/getpath.c.
You should also add documentation.
msg117345 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-09-25 03:03
Right, forgot about getpath.c.
Added documentation.
See the latest version of the patch.
Please note that I was unable to test the non-windows compile.
msg117394 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-25 21:34
The patch compiles fine under Linux, but please don't use tabs for indentation of C files.
msg117398 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-09-26 02:13
Sorry, my mistake, I work in a mixed environment.  If there are no objections, I´ll submit this (with fixed whitespace)
msg117437 - (view) Author: Kristján Valur Jónsson (kristjan.jonsson) * (Python committer) Date: 2010-09-27 05:33
Completed in revision 85028
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54119
2010-09-27 05:33:35kristjan.jonssonsetstatus: open -> closed
resolution: accepted
messages: + msg117437
2010-09-26 02:13:48kristjan.jonssonsetmessages: + msg117398
2010-09-25 21:34:36pitrousetmessages: + msg117394
2010-09-25 03:22:50kristjan.jonssonsettitle: Add Py_SetPath API for embeddint python -> Add Py_SetPath API for embedding python
2010-09-25 03:03:43kristjan.jonssonsetfiles: + py_setpath.patch

messages: + msg117345
2010-09-21 09:18:41pitrousetnosy: + pitrou
messages: + msg117041
2010-09-21 06:32:33kristjan.jonssoncreate