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

No module named 'spacy'' error #60

Closed acrigney closed 10 months ago

acrigney commented 11 months ago

Sorry guys I am getting this error I must not have my Python environment setup properly? I am new to this I just tried to run the .net core example, and I get the same error upgrading it to .net 7

        static async Task Main(string[] args)
        {
            // This example demonstrates how Python.Included is able to automatically install a minimal Python
            // environment which it includes as an embedded resource in its .NET assembly file
            // Python.Included is currently fixed to Python 3.7.3 amd64 for windows
            // If you need a different Python version or platform check out the Python.Installer examples!

            // install in local directory
            Installer.InstallPath = Path.GetFullPath(".");

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

            // install the embedded python distribution
            await Installer.SetupPython();

            // install pip3 for package installation
            Installer.TryInstallPip(true);

            // download and install Spacy from the internet
            Installer.PipInstallModule("spacy");

            // 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);

            // call spacy
            dynamic spacy = Py.Import("spacy"); // throws No module named 'spacy''
            Console.WriteLine("### Spacy version:\n\t" + spacy.__version__);

            Console.WriteLine("\nDone. Press any key to exit.");
#if NETFRAMEWORK
            Console.ReadKey();
#endif
        }
henon commented 11 months ago

Try installing spacy from the command line in the directory where Python.Included installed the embedded python distribution and see if it works. If not you know more.

If it works manually then you'd have to debug with the Python.Included source code to find out what's going on.

acrigney commented 11 months ago

Thanks mate but isn't the framework supposed to do the install when you call the install function?

On Thu, 26 Oct 2023, 11:49 pm Meinrad Recheis, @.***> wrote:

Try installing spacy from the command line in the directory where Python.Included installed the embedded python distribution and see if it works. If not you know more.

If it works manually then you'd have to debug with the Python.Included source code to find out what's going on.

— Reply to this email directly, view it on GitHub https://github.com/henon/Python.Included/issues/60#issuecomment-1781057530, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABCSC7JPID6M2DSLQLZZSRLYBJL4PAVCNFSM6AAAAAA6RD3HWOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBRGA2TONJTGA . You are receiving this because you authored the thread.Message ID: @.***>

henon commented 10 months ago

Yes, I found the error. It was a bug in RunCommand which is called by PipInstallModule and caused pip not to unstall any libraries. It is fixed now.

henon commented 10 months ago

https://www.nuget.org/packages/Python.Deployment/2.0.5 https://www.nuget.org/packages/Python.Included/3.11.6