python / python/cpython

Embedded interpreters: No way to extend `sys.path`

Open
#128,352 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic-subinterpreters type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

Setting up an embedded Python interpreter often involves augmenting sys.path with some application-specific subdirectories, so as not to pollute the system's normal Python installation.

Unfortunately, PyConfig only affords either replacing the default path wholesale, or leaving it as-is (via module_search_paths_set). There appears to be no way to augment sys.path with application-specific directories and no documented way to retrieve the default contents of sys.path.

A workable solution might be to enhance cfg.module_search_paths_set so that when it's set to 2 or 3, the application's paths shall be prepended / appended to sys.path instead of replacing it.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/embedding-how-do-i-extend-sys-path/75734

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PyConfig documentation and the module_search_paths_set behavior described in the issue, then read the linked Discourse discussion for prior design context. Define how application-specific paths should be combined with the default sys.path and what the documented API behavior should be; completion should include an agreed implementation and corresponding documentation or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.