Skip to content

[py] Initialize site, and use PYTHONHOME#390

Merged
masci merged 2 commits intomasterfrom
olivielpeau/set-pythonhome
Jul 19, 2017
Merged

[py] Initialize site, and use PYTHONHOME#390
masci merged 2 commits intomasterfrom
olivielpeau/set-pythonhome

Conversation

@olivielpeau
Copy link
Copy Markdown
Member

@olivielpeau olivielpeau commented Jul 18, 2017

What does this PR do?

  • Allows python to automatically initialize site when we initialize
    the interpreter (see https://docs.python.org/2/library/site.html).
    This makes python build its own default PYTHONPATH from the
    PYTHONHOME (so that it can load all the modules: built-ins,
    site-packages modules, etc).
  • Instead of setting PYTHONPATH (since we let python build that on
    its own), sets PYTHONHOME. That'll set up the embedded python's home, and
    the rest will be handled by python.

See https://docs.python.org/2/using/cmdline.html#envvar-PYTHONHOME:

When PYTHONHOME is set to a single directory, its value replaces both prefix and exec_prefix

Motivation

Disabling site initialization is error-prone. In my case, the installed supervisor
module couldn't be imported because without site initialization, python doesn't
take into account the .pth files in its site-packages directory (and the supervisor
module relies on such a file).

Instead, let's enable the default behavior and let the interpreter do everything.

Additional Notes

This changes the site initialization behavior that was introduced in #15.

Also, sneaked in the addition of a log line that helped me for troubleshooting
(not directly related to the PYTHONPATH change though)

* Allow python to automatically initialize `site` when we initialize
the interpreter (see https://docs.python.org/2/library/site.html).
This makes python build its own default `PYTHONPATH` from the
`PYTHONHOME`, so that it can load modules (built-ins, `site-packages`
modules, etc).
* Instead of setting `PYTHONPATH` (since we let python build that on
its own), set `PYTHONHOME`. That'll pick up the embedded python, the
rest will be handled by python.
@olivielpeau olivielpeau requested a review from masci July 18, 2017 21:04
@masci
Copy link
Copy Markdown
Contributor

masci commented Jul 19, 2017

cc @derekwbrown this should address your issue

@masci masci merged commit c3e39a9 into master Jul 19, 2017
@masci masci deleted the olivielpeau/set-pythonhome branch July 19, 2017 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants