-
Notifications
You must be signed in to change notification settings - Fork 747
Appending library directory to PythonPath causes crash #2325
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
By no means an expert, in fact been using this for a day lol private void InitModules()
{
using var py = Py.GIL();
_sys = Py.Import(SysModuleName);
if (_sys == null)
{
_logger.LogError($"Failed to import Python module: {SysModuleName}");
return;
}
_sys.path.append(Path.Combine(AppContext.BaseDirectory, "python"));
_rtn = Py.Import(RtnModuleName);
if (_rtn == null)
{
_logger.LogError($"Failed to import Python module: {RtnModuleName}");
}
}
```
Where the packages I have bundled are in a python folder that gets copied to output dir |
Do you have any solution? |
On Windows you should be able to see the crash by debugging your app with mixed-mode debugging (or just native debugging) turned on. At least we need to know what kind of crash you experience. |
I solved this problem in a very clever way. You want to include a custom path in the path so that PythonNet can find the custom Python script. Instead, you can use (sys.path.append(path)) to add a custom path to it. |
As crash data was not provided, this issue is not actionable from our side. |
Environment
Details
The Python my app calls has a number of dependencies. For predictability, I want to bundle the dependencies with my app, rather than obtain them via pip at runtime. I gathered the entire dependency tree, as well as the .py file with the code I plan to directly call, and added it all to my Visual Studio project, using build action "Content" and CopyToOutputDirectory=PreserveNewest for each item.
If I didn't need these dependencies, I would call:
That works great. But since I do require the dependencies, I append their root folder to PythonPath first:
Simply appending libPath to PythonPath causes my app to crash on execution of PythonEngine.Initialize();
Is there a recommended way to obtain the traceback? The crash causes the app to exit immediately, there is no exception caught by the debugger. I am more than happy to gather any diagnostic info needed.
The text was updated successfully, but these errors were encountered: