Add function to set Py_NoSiteFlag global variable to 1#971
Merged
filmor merged 4 commits intopythonnet:masterfrom Oct 23, 2019
Merged
Add function to set Py_NoSiteFlag global variable to 1#971filmor merged 4 commits intopythonnet:masterfrom
filmor merged 4 commits intopythonnet:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #971 +/- ##
=======================================
Coverage 86.71% 86.71%
=======================================
Files 1 1
Lines 301 301
=======================================
Hits 261 261
Misses 40 40
Continue to review full report at Codecov.
|
filmor
reviewed
Oct 18, 2019
AlexCatarino
pushed a commit
to QuantConnect/pythonnet
that referenced
this pull request
Jun 27, 2020
* Add function to set Py_NoSiteFlag global variable to 1. * Add myself to authors, update changelog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm using pythonnet to embed python 3.6 in a C# WPF application. I'm effectively booting up a venv with pythonnet and I noticed the user site folder kept getting included in
sys.path.There is a command line argument to disable this, (-S, more info here: https://docs.python.org/3/using/cmdline.html#id3) but as pythonnet loads python directly, this won't work.
There is a way to access this flag with the C API, info here: https://docs.python.org/3/c-api/init.html#c.Py_NoSiteFlag
This is a global variable that is exported, defined here: https://github.com/python/cpython/blob/3.6/Include/pydebug.h
My particular use case is for python 3.6, but it appears this flag is present in 2.7 and all currently supported 3.x versions.
Here is an example on how I am using this addition:
It seems to do the business and I no longer get the user site package path in
sys.path.Note: I'm not quite sure how to test this addition as really is dependent on the user's environment. Perhaps a test to verify the global var is set to 1? Please let me know your thoughts.