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
313 stars 51 forks source link

When trying to install some packages from pip, ModuleNotFoundError: No module named 'pyexpat' occurs. #47

Closed vilmire closed 1 year ago

vilmire commented 1 year ago
static async Task Main(string[] args)
{
    Installer.LogMessage += Installer_LogMessage;;
    Installer.InstallPath = Path.GetFullPath(".");
    await Installer.SetupPython(true);
    PythonEngine.Initialize(new List<string>() { }, true,true);
    dynamic os = Py.Import("os");
    await Installer.TryInstallPip();
    await Installer.PipInstallModule("stable-baselines3[extra]"); //or gym
}

File "importlib__init.py", line 126, in import_module File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1128, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_framesremoved File "C:\Users\vilmire\AppData\Local\Temp\pip-build-env-g55qiue\overlay\Lib\site-packages\setuptools\init.py", line 16, in import setuptools.version File "C:\Users\vilmire\AppData\Local\Temp\pip-build-env-g55qiue_\overlay\Lib\site-packages\setuptools\version.py", line 1, in import pkgresources File "C:\Users\vilmire\AppData\Local\Temp\pip-build-env-g55qiue\overlay\Lib\site-packages\pkg_resources\init__.py", line 32, in import plistlib File "plistlib.py", line 61, in File "xml\parsers\expat.py", line 4, in ModuleNotFoundError: No module named 'pyexpat'

bin\Debug\net7.0\python-3.11.0-embed-amd64 contains pyexpat.pyd and i tried copy it and renamed _pyexpat.pyd . but result was same

vilmire commented 1 year ago

I copied all the .pyd's and pasted where the error occurred.


string[] pydExtFiles = Directory.EnumerateFiles(Installer.EmbeddedPythonHome).Where(x => x.EndsWith(".pyd")).ToArray();

foreach (string pydExtFile in pydExtFiles)
{
  string fileName = Path.GetFileName(pydExtFile);
  File.Copy(pydExtFile, $"{Installer.EmbeddedPythonHome}\\Lib\\site-packages\\pip\\_vendor\\pep517\\in_process\\{fileName}");
}

It works now, but pip doesn't seem to know where pyexpat is.

henon commented 1 year ago

so you are saying it is a pip problem, not a Python.Included issue?

vilmire commented 1 year ago

I dont know. i just copied file and it worked.

henon commented 1 year ago

OK, I am closing this issue. Hopefully it will help others having the same problem with deploying this particular python library.