Skip to content
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

Python.Runtime.BadPythonDllException #54

Open
woaidianqian opened this issue Jun 20, 2023 · 7 comments
Open

Python.Runtime.BadPythonDllException #54

woaidianqian opened this issue Jun 20, 2023 · 7 comments

Comments

@woaidianqian
Copy link

using System;
using System.IO;
using System.Threading.Tasks;
using Python.Runtime;

namespace Python.Deployment.Download
{
class Program
{
static async Task Main(string[] args)
{
// ================================================
// This example demonstrates how to download a Python distribution (v2.7.9) and install it locally
// ================================================

        // set the download source
        Python.Deployment.Installer.Source = new Deployment.Installer.DownloadInstallationSource()
        {
            DownloadUrl = @"https://www.python.org/ftp/python/3.7.3/python-3.7.3-embed-amd64.zip",
        };

        // install in local directory. if you don't set it will install in local app data of your user account
        Python.Deployment.Installer.InstallPath = Path.GetFullPath(".");

        // see what the installer is doing
        Python.Deployment.Installer.LogMessage += Console.WriteLine;

        // install from the given source
        await Python.Deployment.Installer.SetupPython();

        // ok, now use pythonnet from that installation
        PythonEngine.Initialize();

        // call Python's sys.version to prove we are executing the right version
        dynamic sys=Py.Import("sys");
        Console.WriteLine("### Python version:\n\t" + sys.version);

        // call os.getcwd() to prove we are executing the locally installed embedded python distribution
        dynamic os = Py.Import("os");
        Console.WriteLine("### Current working directory:\n\t" + os.getcwd());
        Console.WriteLine("### PythonPath:\n\t" + PythonEngine.PythonPath);

    }
}

}

PythonEngine.Initialize();
error!!!

Python.Runtime.BadPythonDllException:“Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL. See https://github.com/pythonnet/pythonnet#embedding-python-in-net”

@henon
Copy link
Owner

henon commented Jun 20, 2023

did you compile this for x86 ?

@henon
Copy link
Owner

henon commented Jun 20, 2023

You may have to set this
image

@woaidianqian
Copy link
Author

image
I have already set it to x64, but the problem still persists. If I don't specify the Python version, it will automatically download Python 3.11 without any error. However, when I specify the Python version, it throws an error.

@woaidianqian
Copy link
Author

woaidianqian commented Jun 21, 2023

using System;
using System.Threading.Tasks;
using Python.Included;
using Python.Runtime;

namespace NetCoreExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            await Installer.SetupPython();
            PythonEngine.Initialize();
            dynamic sys=PythonEngine.ImportModule("sys");
            Console.WriteLine("Python version: " + sys.version);
        }
    }
}
dynamic sys=PythonEngine.ImportModule("sys");

The last line should be changed to:

dynamic sys=Py.Import("sys")

@henon
Copy link
Owner

henon commented Jun 21, 2023

and that solves it?

@woaidianqian
Copy link
Author

There is no error when the program automatically downloads python, and if you want to set the python version by yourself, it is still not solved

@henon
Copy link
Owner

henon commented Jun 21, 2023

I guess the newer version of pythonnet doesn't work with old python versions any more?

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