Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing numpy leads to ModuleNotFoundError #270

Closed
SeRealMF opened this issue Oct 3, 2023 · 6 comments
Closed

Importing numpy leads to ModuleNotFoundError #270

SeRealMF opened this issue Oct 3, 2023 · 6 comments
Assignees

Comments

@SeRealMF
Copy link
Contributor

SeRealMF commented Oct 3, 2023

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
Copy link
Member

j042 commented Nov 6, 2023

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
Copy link
Member

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

@SeRealMF
Copy link
Contributor Author

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
Copy link
Member

j042 commented Nov 15, 2023

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
Copy link
Member

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

@SeRealMF
Copy link
Contributor Author

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.

@j042 j042 closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants