Skip to content

Two differnt exceptions on x64 and x86 in VS calling python script #478

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

Closed
keowang opened this issue May 30, 2017 · 19 comments
Closed

Two differnt exceptions on x64 and x86 in VS calling python script #478

keowang opened this issue May 30, 2017 · 19 comments

Comments

@keowang
Copy link

keowang commented May 30, 2017

Environment

  • Pythonnet version: 2.3.0 installed through nugget pythonnet_py35_dotnet
  • Python version: 3.5.3
  • Operating System: Win10

Details

Running Embedding Python in .NET on x86 Py.GIL() triggers the following:
An unhandled exception of type 'System.DllNotFoundException' occurred in Python.Runtime.dll

Additional information: Unable to load DLL 'python35': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

on x64 a different one:
An unhandled exception of type 'System.BadImageFormatException' occurred in mscorlib.dll

Additional information: Could not load file or assembly 'Python.Runtime, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Searched for the similar issues some are pointing to the Nuget error in switching platforms but if that's the case one of the two should work right?

where python: C:\Users\XXX\AppData\Local\Programs\Python\Python35\python.exe
python --version: Python 3.5.3

%PYTHON_HOME%: C:\Users\XXX\AppData\Local\Programs\Python\Python35
%PYTHONPATH%: C:\Users\XXXX\AppData\Local\Programs\Python\Python35\Lib

The only thing I want to do is to call Python scripts from C# application. It would be great if there is a simple short cut.

@keowang
Copy link
Author

keowang commented May 30, 2017

default key in InstallPath: C:\Users\XXXX\AppData\Local\Programs\Python\Python35\python.exe
default key in PythonPath: C:\Users\XXXX\AppData\Local\Programs\Python\Python35\DLLs\

@den-run-ai
Copy link
Contributor

we found last week that VS does not switch architecture for Nuget installed package. You have to do it manually:

#472

@keowang
Copy link
Author

keowang commented May 30, 2017

#472 I saw that one and it was not clear to me how to update manually would you please elaborate a bit more? Thanks!

@den-run-ai
Copy link
Contributor

den-run-ai commented May 30, 2017 via email

@keowang
Copy link
Author

keowang commented May 30, 2017

Here is what I did you can correct me whenever I am wrong:

  1. save the Python.Runtime.dll from x64
  2. uninstall the pythonnet nugget package completely from my application
  3. add Python.Runtime.dll into my application by right-clicking reference and add reference
  4. run example code again same error.
    Where I got wrong? Thanks!

@keowang
Copy link
Author

keowang commented May 30, 2017

Also you are not answering my question why is it two different errors if it were for the architecture compatibility issue one of the two should be working shouldn't it?

@den-run-ai
Copy link
Contributor

I just checked and it is working fine with 64-bit Python 3.5. You can only use x64 or x86 corresponding to Python architecture, so can you show full output of python --version?

@keowang
Copy link
Author

keowang commented May 30, 2017

C:\Users\XXXX>python --version
Python 3.5.3

I installed the 64 bit python which did not work with either x64 or x86

@keowang
Copy link
Author

keowang commented May 30, 2017

Specifically on x64 it's complaining

An unhandled exception of type 'System.DllNotFoundException' occurred in Python.Runtime.dll

Additional information: Unable to load DLL 'python35': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

@den-run-ai
Copy link
Contributor

den-run-ai commented May 30, 2017 via email

@keowang
Copy link
Author

keowang commented May 30, 2017

like this:
pip install git+https://github.com/pythonnet/pythonnet
?

@den-run-ai
Copy link
Contributor

den-run-ai commented May 30, 2017 via email

@keowang
Copy link
Author

keowang commented May 30, 2017

Hay, this thing is killing me I would appreciate if you bear with me.

  1. pip install pythonnet-2.3.0-cp35-cp35m-win_amd64.whl
  2. add Python.Runtime.dll from C:\Users\XXX\AppData\Local\Programs\Python\Python35\Lib\site-packages to my C# application
  3. run example again. Exactly same error.

@den-run-ai
Copy link
Contributor

den-run-ai commented May 30, 2017 via email

@keowang
Copy link
Author

keowang commented May 30, 2017

"Installed CPython is reachable by %PATH% or %PYTHONHOME% environment variables."

Maybe change the or to and since PYTHON_HOME is added to PATH? It worked, thanks very much!

@den-run-ai
Copy link
Contributor

Pythonhome is needed for embedding python, while python in path is only when starting the Python interpreter.

@keowang
Copy link
Author

keowang commented May 31, 2017

last question, would python3.6 work with pythonnet-2.3.0-cp35?

@den-run-ai
Copy link
Contributor

den-run-ai commented May 31, 2017 via email

@keowang
Copy link
Author

keowang commented May 31, 2017

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants