henon / Python.Included

A Python.NET based framework enabling .NET libraries to call into Python packages without depending on a local Python installation.
MIT License
321 stars 52 forks source link

Custom `InstallDirectory` is not used when extracting Python #40

Closed JimiC closed 2 years ago

JimiC commented 2 years ago

I was trying to install Python at a custom folder, resulting in pythonnet not finding the dll of Python, simply because Python files get not extracted to the custom folder.

private static async Task Main() {
        Installer.InstallPath = Directory.GetCurrentDirectory();
        Installer.InstallDirectory = "python3.7";
        await Installer.SetupPython();
        using (Py.GIL()) { }
    }

The code in question is https://github.com/henon/Python.Included/blob/f6338cf795a6919f88d87018582e292246c1035e/Python.Deployment/Installer.cs#L91

when it should use

ZipFile.ExtractToDirectory(zip, PythonDirectoryName));
henon commented 2 years ago

Thanks!

https://www.nuget.org/packages/Python.Included/3.10.0-preview3 https://www.nuget.org/packages/Python.Deployment/1.4.0

JimiC commented 2 years ago

@henon I need to apologize. PythonDirectoryName is not the correct property to use but EmbeddedPythonHome is, as you use in https://github.com/henon/Python.Included/blob/eb0cce2a7599a23e38cfb669cd86abff04ca37e2/Python.Deployment/Installer.cs#L96.

PythonDirectoryName does not include the InstallPath and it will try to extract the zip at the current working directory.

Really sorry.

JimiC commented 2 years ago

@henon As I was afraid. If you use only the Python.Deployment library and don't set PythonDirectoryName the code crashes. Using Python.Included on the other hand fortunately has a default value for InstallDirectory that prevents the crash.

Any chance you can fix that?

henon commented 2 years ago

Sure, no problem https://www.nuget.org/packages/Python.Deployment/1.5.0 https://www.nuget.org/packages/Python.Included/3.10.0-preview5