Skip to content

Cannot import clr from Python due to DllNotFoundException after setting paths #1297

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
christabella opened this issue Nov 26, 2020 · 1 comment

Comments

@christabella
Copy link
Contributor

Environment

  • Pythonnet version: 3.0 (ongoing, latest master branch)
  • Python version: 3.7.9
  • Operating System: Windows 10, 64bit, WinPE

Details

I've gone through https://github.com/pythonnet/pythonnet/wiki/Troubleshooting-on-Windows,-Linux,-and-OSX#common-errors and the issues listed there, #259 #463 #467

However, they are for embedding CPython within a .NET application whereas I would like to get the import clr statement working. Furthermore, I have installed CPython 3.8.6 and got its location with import sys; sys.executable and set that to PATH, PYTHONHOME, and PYTHONPATH environment variables.

image

Also my VS configuration is:
image

However,

>>> import clr
Attempting to load 'Python.Runtime' using standard binding rules.
'Python.Runtime' not found using standard binding rules.
Attempting to load Python.Runtime from: 'C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\Python.Runtime.dll'.
Success loading 'Python.Runtime' from: 'C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\Python.Runtime.dll'.

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load DLL 'python3.8': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Python.Runtime.Runtime.Py_IsInitialized()
   at Python.Runtime.Runtime.Initialize(Boolean initSigs, ShutdownMode mode)
   at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs, ShutdownMode mode)
   at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv, Boolean initSigs, ShutdownMode mode)
   at Python.Runtime.PythonEngine.InitExt()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at clrModule.PyInit_clr()
@christabella
Copy link
Contributor Author

Seems like this can be resolved by adding the WINDOWS flag to the conditional compilation symbols when building the Python.NET project in Visual Studio.

For posterity, the full instructions are image

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

1 participant