10000 PythonEngine.PythonHome doesn't work · Issue #708 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

PythonEngine.PythonHome doesn't work #708

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
fandrei opened this issue Jul 28, 2018 · 8 comments
Closed

PythonEngine.PythonHome doesn't work #708

fandrei opened this issue Jul 28, 2018 · 8 comments

Comments

@fandrei
Copy link
fandrei commented Jul 28, 2018

Environment

Pythonnet version: 2.3.0
Python version: 3.6
Operating System: Windows 7 x64

Details

Trying to run this C# program:

			var pythonPath = @"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\";

			PythonEngine.PythonHome = pythonPath;

			using (Py.GIL())
			{
				dynamic np = Py.Import("numpy");
				Console.WriteLine(np.cos(np.pi * 2));
			}

and getting this exception:

System.DllNotFoundException: 'Unable to load DLL 'python36': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
@den-run-ai
Copy link
Contributor

Please read this comment from the issue linked in the wiki:

#259 (comment)

@fandrei
Copy link
Author
fandrei commented Jul 28, 2018

@denfromufa it's a workaround; and that still means that PythonEngine.PythonHome doesn't work, does it?

@den-run-ai
Copy link
Contributor

Please refer to official CPython embedding API if you think that this behavior is not correct and then contributions are welcome!

@fandrei
Copy link
Author
fandrei commented Jul 28, 2018

@denfromufa I'm already contributing by testing your code.

Well, this workaround doesn't work properly too:

			var pythonPath = @"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python3_64";

			Environment.SetEnvironmentVariable("PATH", $@"{pythonPath};" + Environment.GetEnvironmentVariable("PATH"));
			Environment.SetEnvironmentVariable("PYTHONHOME", pythonPath);
			Environment.SetEnvironmentVariable("PYTHONPATH ", $@"{pythonPath}\Lib");

			using (Py.GIL())
			{
				dynamic np = Py.Import("numpy");
				Console.WriteLine(np.cos(np.pi * 2));
			}
System.DllNotFoundException: 'Unable to load DLL 'python36': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

The DLL file does exist at the specified path.

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64>attrib python36.dll
A            C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\python36.dll

@den-run-ai
Copy link
Contributor

Are you mixing two different Python installations Python3_64 and Anaconda3_64?!

@fandrei
Copy link
Author
fandrei commented Jul 28, 2018

@denfromufa in this sample, only one installation is used. The path C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python3_64 is correct and C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python36.dll does exist.

@fandrei
Copy link
Author
fandrei commented Jul 28, 2018

Ah, now I see. My bad. PATH workaround works, PythonEngine.PythonHome throws an exception.

@epignatelli
Copy link
epignatelli commented Jul 9, 2020

Would it be better to reopen this issue?

The only solution is actually a workaround. Also, why is PythonEngine.PythonPath = "" not working?
Any plan to fix it?

Or any place I can start looking at to fix it?

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

3 participants
0