tataratat / splinepy

Library for prototyping spline geometries of arbitrary dimensions and degrees, and IGA
https://tataratat.github.io/splinepy
Other
47 stars 13 forks source link

Importing numpy leads to ModuleNotFoundError #270

Closed SeRealMF closed 10 months ago

SeRealMF commented 1 year ago

When executing npz.py in splinepy/io a ModuleNotFoundError will be raised.

This is because of the following line of code: import numpy as np

Numpy is using json but because of the fact that json.py is another file in the splinepy/io folder, it will therefore execute this file instead. This leads to the following error message:

Traceback (most recent call last):
  File "...\splinepy\splinepy\io\npz.py", line 11, in <module>
    import numpy as np
  File "...\AppData\Local\python\mu\mu_venv-38-20221219-011508\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import core
  File "...\AppData\Local\python\mu\mu_venv-38-20221219-011508\lib\site-packages\numpy\core\__init__.py", line 9, in <module>
    from numpy.version import version as __version__
  File "...\AppData\Local\python\mu\mu_venv-38-20221219-011508\lib\site-packages\numpy\version.py", line 3, in <module>
    from ._version import get_versions
  File "...\AppData\Local\python\mu\mu_venv-38-20221219-011508\lib\site-packages\numpy\_version.py", line 7, in <module>
    import json
  File "...\splinepy\splinepy\io\json.py", line 10, in <module>
    from splinepy import settings
ModuleNotFoundError: No module named 'splinepy'
j042 commented 11 months ago

This is very rare use-case. In general, I'd like to add leading underscore to module local imports, then these things shouldn't happen.

clemens-fricke commented 11 months ago

I was not able to reproduce this error at all. Even with a completely clean environment.

SeRealMF commented 11 months ago

I was successfully able to reproduce the error, though only on Windows, not on Linux. There may also be many other factors that influence whether the error appears or not.

j042 commented 11 months ago

This is very rare use-case. In general, I'd like to add leading underscore to module local imports, then these things shouldn't happen.

Would still happen with json as it has the same name as built-in module. For this one, we will have to add a trailing underscore. You can add this to #296.

clemens-fricke commented 11 months ago

After merging #309, does this issue persist? Could you check this @SeRealMF and close this issue if the problem is fixed?

SeRealMF commented 11 months ago

The issue still persists, even with the latest changes. @j042 mentioned a trailing underscore, though the issue seems resolved in my opinion with a leading underscore of json.py. No errors occur when the file is named _json.py.
Again, in my case all those notes apply only to Windows. No problems on Linux.