Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add function to set Py_NoSiteFlag global variable to 1#971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
filmor merged 4 commits intopythonnet:masterfromalexhelms:setnositeflag
Oct 23, 2019

Conversation

alexhelms
Copy link
Contributor

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 insys.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:

PythonEngine.PythonHome = pythonHome;PythonEngine.PythonPath = pythonPath;PythonEngine.SetNoSiteFlag();PythonEngine.Initialize();

It seems to do the business and I no longer get the user site package path insys.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.

@codecov-io
Copy link

codecov-io commentedOct 17, 2019
edited
Loading

Codecov Report

Merging#971 intomaster willnot change coverage.
The diff coverage isn/a.

Impacted file tree graph

@@           Coverage Diff           @@##           master     #971   +/-   ##=======================================  Coverage   86.71%   86.71%           =======================================  Files           1        1             Lines         301      301           =======================================  Hits          261      261             Misses         40       40
FlagCoverage Δ
#setup_linux65.44% <ø> (ø)⬆️
#setup_windows71.42% <ø> (ø)⬆️

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update4a9457f...e341336. Read thecomment docs.

@filmorfilmor merged commitf2e6f6f intopythonnet:masterOct 23, 2019
AlexCatarino pushed a commit to QuantConnect/pythonnet that referenced this pull requestJun 27, 2020
* Add function to set Py_NoSiteFlag global variable to 1.* Add myself to authors, update changelog.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@filmorfilmorfilmor left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@alexhelms@codecov-io@filmor

[8]ページ先頭

©2009-2025 Movatter.jp