You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have many Conda Python environments, and I have installed PythonNet in only one of them.
I installed PythonNet using "conda install -c pythonnet pythonnet", and the Python.Runtime.dll is located in a conda environment named anaconda3: "C:\Users\username\Miniconda3\envs\anaconda3\Lib\site-packages"
In Visual Studio, I added a reference to the DLL and tried to follow the Embedding Python in .NET" example. My root Conda environment with no external libraries installed is running Python 3.6, so it is no surprise I was getting "Unable to load DLL 'python35'.
I went ahead and downgraded the base Conda environment to 3.5 and captured the PythonEngine.PythonPath variable and see it is pointing to the following paths:
"C:\Users\username\Miniconda3\python35.zip;C:\Users\username\Miniconda3\Lib;C:\Users\username\Miniconda3\DLLs;C:\Users\username\Documents\Visual Studio 2015\Projects\WindowsFormsApplication4\WindowsFormsApplication4\bin\x64\Debug"
So it appears that installing PythonNet in a conda environment and simply pointing to the DLL is insufficient. Is there any way to add the correct paths to the PythonEngine? I was unable to find any documentation on this.
@gemiko did you activate your env. before calling it for embedding in .NET at runtime? what errors and tracebacks did you get? what does conda env list show?
Finally before PythonEngine.Initialize() call you can set PythonHome property:
I tried every possible thing written on this page but nothing worked. Still getting this issue
System.DllNotFoundException: 'Unable to load DLL 'python35': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
I have download pythonnet and python3.5 nuget package and trying to embed python in >net environment.
@shrishar i don't think anyone tested the python3.5 nuget package with pythonnet, but there should not be anything special about it. just make sure to match the architecture x86/x64.
Okay.. can you provide me the code and step by step by procedure for
setting up python home and path environment variable because as of now I am
following the above code and I am still getting error. It is driving me
nuts now.
I have to resolve this issue. 😪
Is there any additional documentation on how to call python FROM C#? I have struggled with everything listed here and still cannot get this working. I have installed pythonnet into a python 3.6 environment running in Conda. I can access the clr FROM python, but really need to call python FROM C#.
I finally found that I needed to include "Python.Runtime.dll", but it was unclear from WHERE (I found it here: "C:\Anaconda\envs\cvpy36\Lib\site-packages" and assume that is what I need. (It would be helpful to include this information on the main pythonnet documentation page).
I was able to get through the "Unable to load DLL" errors by using the code that gemiko supplied above, but now as soon as I call PythonEngine.Initialize() the application quits (no errors, no messages, nothing).
Any suggestions, or link to more detailed step-by-step instructions on how to make this work in C# (something that includes adding the correct references, "using" statements, etc.)?
Thanks!
---- EDIT ----
I found the issue and want to leave this here for others.
It seems you have to set the environment variable, but you ALSO need to set PythonHome for the PythonEngine (I assumed this would get set from the environment variable, as PythonEngine cannot be called without it).
@GafferMan yes, and anaconda can mess up few other things when embedding its Python via pythonnet. I prefer to use vanilla CPython for embedding use cases. There are now wheels for almost any packages, albeit not highly optimized.
@shrishar i don't think anyone tested the python3.5 nuget package with pythonnet, but there should not be anything special about it. just make sure to match the architecture x86/x64.
Oh, Jesus Christ.
The only point for me was the architecture type!
Activity
den-run-ai commentedon May 11, 2017
@gemiko thanks for trying pythonnet! Search this issue tracker for
%pythonhome%examples.den-run-ai commentedon May 11, 2017
here is wiki entry about:
https://github.com/pythonnet/pythonnet/wiki/Troubleshooting-on-Windows-and-Linux#cpython-27-36-installed
den-run-ai commentedon May 13, 2017
@gemiko did you activate your env. before calling it for embedding in .NET at runtime? what errors and tracebacks did you get? what does
conda env listshow?Finally before
PythonEngine.Initialize()call you can setPythonHomeproperty:pythonnet/src/runtime/pythonengine.cs
Line 74 in 7db41a9
den-run-ai commentedon May 19, 2017
@gemiko would you mind summarizing your tutorial in wiki? this is great resource asked many times here!
filmor commentedon Jul 11, 2017
This looks solved, feel free to reopen if that isn't the case.
shrishar commentedon Aug 7, 2018
Hi Everyone,
I tried every possible thing written on this page but nothing worked. Still getting this issue
System.DllNotFoundException: 'Unable to load DLL 'python35': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
I have download pythonnet and python3.5 nuget package and trying to embed python in >net environment.
Please help
Thanks,
Divya
den-run-ai commentedon Aug 8, 2018
@shrishar i don't think anyone tested the python3.5 nuget package with pythonnet, but there should not be anything special about it. just make sure to match the architecture x86/x64.
shrishar commentedon Aug 8, 2018
GafferMan commentedon Dec 31, 2018
Is there any additional documentation on how to call python FROM C#? I have struggled with everything listed here and still cannot get this working. I have installed pythonnet into a python 3.6 environment running in Conda. I can access the clr FROM python, but really need to call python FROM C#.
I finally found that I needed to include "Python.Runtime.dll", but it was unclear from WHERE (I found it here: "C:\Anaconda\envs\cvpy36\Lib\site-packages" and assume that is what I need. (It would be helpful to include this information on the main pythonnet documentation page).
I was able to get through the "Unable to load DLL" errors by using the code that gemiko supplied above, but now as soon as I call PythonEngine.Initialize() the application quits (no errors, no messages, nothing).
Any suggestions, or link to more detailed step-by-step instructions on how to make this work in C# (something that includes adding the correct references, "using" statements, etc.)?
Thanks!
---- EDIT ----
I found the issue and want to leave this here for others.
It seems you have to set the environment variable, but you ALSO need to set PythonHome for the PythonEngine (I assumed this would get set from the environment variable, as PythonEngine cannot be called without it).
Adding the line:
fixed it.
den-run-ai commentedon Dec 31, 2018
@GafferMan yes, and anaconda can mess up few other things when embedding its Python via pythonnet. I prefer to use vanilla CPython for embedding use cases. There are now wheels for almost any packages, albeit not highly optimized.
AliKar97 commentedon Aug 25, 2019
Oh, Jesus Christ.
The only point for me was the architecture type!
My working solutions:
HERE_01
HERE_02