indygreg / PyOxidizer

A modern Python application packaging and distribution tool
Mozilla Public License 2.0
5.4k stars 234 forks source link

ngsolve, module not found #650

Open GlennWSo opened 1 year ago

GlennWSo commented 1 year ago

Im trying to create app that depends on ngsolve. My targets are both windows and linux.

To test my that i get the depenencies working i have made a simple pyoxidzer.bzl config. Here a link: https://github.com/GlennWSo/pyoxidzer-learn/blob/ngsolve/pyoxidizer.bzl Bellow here is a snippet from the file:

def make_exe():
    dist = default_python_distribution(python_version="3.9")
    policy = dist.make_python_packaging_policy()
    policy.set_resource_handling_mode("files")
    policy.resources_location_fallback = "filesystem-relative:lib"

    python_config = dist.make_python_interpreter_config()
    python_config.module_search_paths = ["$ORIGIN/lib"]

    exe = dist.to_python_executable(
        name = "python-with-ngsolve",
        packaging_policy = policy,
        config = python_config,
    )

    for resource in exe.pip_download(["pyvista", "ngsolve"]):
        resource.add_location = "filesystem-relative:lib"
        exe.add_python_resource(resource)

    return exe

What i expect when i enter "pyoxidzer run" is a python shell where i can import ngsolve and pyvista. but what happens:

foo@bar:~ $ pyoxidizer run
printing lots of info...
...
Python 3.9.13
Type "help" to ...
>>> import pyvista
>>> print(pyvista.__version)
0.36.1
# pyvista package is working :)

>>> import ngsolve
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'ngsolve'
# :(

Any help would be much appreciated!

GlennWSo commented 1 year ago

more probing of the oxidized python shell gives:

>>> import pkg_resources
>>> for pack in pkg_resources.working_set:
...     print(pack)
...
tbb 2021.7.0
mkl 2021.4.0
intel-openmp 2021.4.0
attrs 22.1.0
packaging 21.3
vtk 9.2.2
Pillow 9.2.0
ngsolve 6.2.2204
netgen-mesher 6.2.2203.post46.dev0
multidict 6.0.2
fonttools 4.37.4
async-timeout 4.0.2
aiohttp 3.8.3
matplotlib 3.6.1
idna 3.4
pyparsing 3.0.9
imageio 2.22.2
python-dateutil 2.8.2
charset-normalizer 2.1.1
numpy 1.23.4
six 1.16.0
wslink 1.8.4
yarl 1.8.1
appdirs 1.4.4
kiwisolver 1.4.4
frozenlist 1.3.1
aiosignal 1.2.0
contourpy 1.0.5
pyvista 0.36.1
cycler 0.11.0
scooby 0.6.0

ngsolve is in this list, so why cant i import it?

GlennWSo commented 1 year ago

update. I found why ngsolve could not be imported. it was not placed in origin/lib but instead in: origin/lib/lib/python3.9/site-packages/lib/ngsolve and some .so files it uses where placed in origin/lib/lib

I dont understand why i get such messy lib tree But i solved my problem by making the fallowing changes: patch