Skip to content

Conda Environments - Wrong Path Captured #463

Closed

Description

Environment

  • Pythonnet version: 2.3
  • Python version: Python 3.5 (Conda environment)
  • Operating System: Windows 10

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.

Activity

  1. den-run-ai commented on May 11, 2017

    @den-run-ai
    Contributor

    @gemiko thanks for trying pythonnet! Search this issue tracker for %pythonhome% examples.

  2. den-run-ai commented on May 11, 2017

    @den-run-ai
    Contributor
  3. den-run-ai commented on May 13, 2017

    @den-run-ai
    Contributor

    @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:

    public static string PythonHome

  4. den-run-ai commented on May 19, 2017

    @den-run-ai
    Contributor

    @gemiko would you mind summarizing your tutorial in wiki? this is great resource asked many times here!

  5. filmor commented on Jul 11, 2017

    @filmor
    Member

    This looks solved, feel free to reopen if that isn't the case.

  6. shrishar commented on Aug 7, 2018

    @shrishar

    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

  7. den-run-ai commented on Aug 8, 2018

    @den-run-ai
    Contributor

    @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.

  8. shrishar commented on Aug 8, 2018

    @shrishar
  9. GafferMan commented on Dec 31, 2018

    @GafferMan

    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:

    PythonEngine.PythonHome = "C:\\Anaconda\\envs\\cvpy36";
    

    fixed it.

  10. den-run-ai commented on Dec 31, 2018

    @den-run-ai
    Contributor

    @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.

  11. AliKar97 commented on Aug 25, 2019

    @AliKar97

    @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!

    My working solutions:
    HERE_01
    HERE_02

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions