-
Notifications
You must be signed in to change notification settings - Fork 748
Conda Environments - Wrong Path Captured #463
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
@gemiko thanks for trying pythonnet! Search this issue tracker for |
here is wiki entry about: |
I attempted to follow this #259 (comment), under my VS2015 environment to set the paths, but didn't work. Setting PYTHONHOME in my system environmental variable to C:\Users\username\Miniconda3\envs\anaconda3 also did not work. The only way PythonNet works for me is by using the root Anaconda environment, which isn't a solution when when I have to manage multiple projects that have their own package requirements which is why I'm using Conda environments. Any other potential solutions? |
@gemiko did you activate your env. before calling it for embedding in .NET at runtime? what errors and tracebacks did you get? what does Finally before pythonnet/src/runtime/pythonengine.cs Line 74 in 7db41a9
|
Inside the commandline, activating the conda environment and then starting visual studio works. However, when deploying the software, I found I absolutely needed to set the PYTHONHOME and PYTHONPATH environment variables. The good thing is that Conda Python environments are standalone and can be deployed with your application. It's just a matter of how to package it all together. Suppose the Python 3.5 environment should be stored in a subdirectory named "Python" one level from the exe, this worked for me:
Adding the following to the Post-Build event command line will mirror the Python environment to the build output directory and complete the build process (Robocopy error codes < 8 are not errors and need to be set to 0 for Visual Studio builds to be successful): Hope this helps others! |
@gemiko would you mind summarizing your tutorial in wiki? this is great resource asked many times here! |
Unfortunately, it stopped working for me. I'll need to investigate it some more. |
Looks like I got it working now. Setting both the PATH and PYTHONHOME to the directory is needed. I'll also edit the above post so there's no confusion for others.
|
This looks solved, feel free to reopen if that isn't the case. |
Hi Everyone, I tried every possible thing written on this page but nothing worked. Still getting this issue Please help Thanks, |
@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. 😪
…On Wed, Aug 8, 2018, 7:04 AM Denis Akhiyarov ***@***.***> wrote:
@shrishar <https://github.com/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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#463 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Ad_-9qxQTxCGpmmKW7pgodF16YLvAzmnks5uOu_TgaJpZM4NXfcH>
.
|
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. |
@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. |
Environment
Details
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.
The text was updated successfully, but these errors were encountered: