Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Trying to use Python DLL results in error. #1989

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
Awire9966 opened this issue Oct 28, 2022 · 2 comments
Closed

Trying to use Python DLL results in error. #1989

Awire9966 opened this issue Oct 28, 2022 · 2 comments

Comments

@Awire9966
Copy link

Awire9966 commented Oct 28, 2022

Environment

  • Pythonnet version: 3.0
  • Python version: 3.11
  • Operating System: Windows 10
  • .NET Runtime: Net Framework 4.7.1

Details

  • Describe what you were trying to get done.

    I was trying to test the features of pythonnet because I was really hopeful for this api.

  • What commands did you run to trigger this issue? If you can provide a
    Minimal, Complete, and Verifiable example
    this will help us understand the issue.

I tried setting the DLL location with the variable and it straight up crashes. I tried using the python38 dll but that gives the same error.

 Unhandled Exception: System.TypeInitializationException: The type initializer for 'Delegates' threw an exception. ---> System.DllNotFoundException: Could not load C:\Users\Awire\source\repos\pythonnettest\pythonnettest\bin\Debug\python311.dll. ---> System.ComponentModel.Win32Exception: %1 is not a valid Win32 application
   --- End of inner exception stack trace ---
   at Python.Runtime.Platform.WindowsLoader.Load(String dllToLoad)
   at Python.Runtime.Runtime.Delegates.GetUnmanagedDll(String libraryName)
   at Python.Runtime.Runtime.Delegates..cctor()
   --- End of inner exception stack trace ---
   at Python.Runtime.Runtime.Delegates.get_Py_IsInitialized()
   at Python.Runtime.Runtime.Py_IsInitialized()
   at Python.Runtime.Runtime.<>c.<Initialize>b__32_0()
   at Python.Runtime.Runtime.TryUsingDll[T](Func`1 op)
   at Python.Runtime.Runtime.Initialize(Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize()
   at pythonnettest.Program.Main(String[] args) in C:\Users\Awire\source\repos\pythonnettest\pythonnettest\Program.cs:line 17C:\Users\Awire\source\repos\pythonnettest\pythonnettest\bin\Debug\python311.dll. ---> System.ComponentModel.Win32Exception: %1 is not a valid Win32 application
   --- End of inner exception stack trace ---
   at Python.Runtime.Platform.WindowsLoader.Load(String dllToLoad)
   at Python.Runtime.Runtime.Delegates.GetUnmanagedDll(String libraryName)
   at Python.Runtime.Runtime.Delegates..cctor()
   --- End of inner exception stack trace ---
   at Python.Runtime.Runtime.Delegates.get_Py_IsInitialized()
   at Python.Runtime.Runtime.Py_IsInitialized()
   at Python.Runtime.Runtime.<>c.<Initialize>b__32_0()
   at Python.Runtime.Runtime.TryUsingDll[T](Func`1 op)
   at Python.Runtime.Runtime.Initialize(Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize()
   at pythonnettest.Program.Main(String[] args) in C:\Users\Awire\source\repos\pythonnettest\pythonnettest\Program.cs:line 17

My C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Python.Runtime;
using Python;
using System.IO;

namespace pythonnettest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Runtime.PythonDLL = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\python311.dll";
            PythonEngine.Initialize();
            PythonEngine.Exec("print('Hello')");
            

        }
    }
}

  • If there was a crash, please include the traceback here.

N/A

@filmor
Copy link
Member

filmor commented Oct 28, 2022

Python 3.11 is not supported yet:

image

You'll have to wait for #1955 to land.

@filmor filmor closed this as completed Oct 28, 2022
@Awire9966
Copy link
Author

Still doesnt work, gives me this error:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Delegates' threw an exception. ---> System.DllNotFoundException: Could not load C:\Users\Awire\source\repos\pythonnettest\pythonnettest\bin\Debug\python310.dll. ---> System.ComponentModel.Win32Exception: %1 is not a valid Win32 application
   --- End of inner exception stack trace ---
   at Python.Runtime.Platform.WindowsLoader.Load(String dllToLoad)
   at Python.Runtime.Runtime.Delegates.GetUnmanagedDll(String libraryName)
   at Python.Runtime.Runtime.Delegates..cctor()
   --- End of inner exception stack trace ---
   at Python.Runtime.Runtime.Delegates.get_Py_IsInitialized()
   at Python.Runtime.Runtime.Py_IsInitialized()
   at Python.Runtime.Runtime.<>c.<Initialize>b__32_0()
   at Python.Runtime.Runtime.TryUsingDll[T](Func`1 op)
   at Python.Runtime.Runtime.Initialize(Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)
   at Python.Runtime.PythonEngine.Initialize()
   at pythonnettest.Program.Main(String[] args) in C:\Users\Awire\source\repos\pythonnettest\pythonnettest\Program.cs:line 17

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