Zuzu-Typ / PyGLM

Fast OpenGL Mathematics (GLM) for Python
zlib License
205 stars 28 forks source link

AttributeError: module 'glm' has no attribute 'vec3' with unittest on ubuntu #208

Closed Wasserwecken closed 1 year ago

Wasserwecken commented 1 year ago

I've created a ci workflow and tests for my libary: https://github.com/Wasserwecken/spatial-transform

Tests are all running on my local windows(11) machine with python 3.9. But they fail all with the same error on wsl and GitHub CI.

Does have PyGLM some extra requirements? You can check the CI file on the repo if needed: https://github.com/Wasserwecken/spatial-transform/blob/main/.github/workflows/python-package.yml

WSL ubuntu 22.04

python3.9 -m unittest discover ./SpatialTransform/tests
EEEE
======================================================================
ERROR: test_euler (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_euler
Traceback (most recent call last):
  File "/usr/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/mnt/e/Code/Privat/Python/spatial-transform/SpatialTransform/tests/test_euler.py", line 4, in <module>
    from SpatialTransform import Euler
  File "/mnt/e/Code/Privat/Python/spatial-transform/SpatialTransform/__init__.py", line 1, in <module>
    from .lib.transform import Transform
  File "/mnt/e/Code/Privat/Python/spatial-transform/SpatialTransform/lib/transform.py", line 5, in <module>
    from .euler import Euler
  File "/mnt/e/Code/Privat/Python/spatial-transform/SpatialTransform/lib/euler.py", line 8, in <module>
    class Euler:
  File "/mnt/e/Code/Privat/Python/spatial-transform/SpatialTransform/lib/euler.py", line 18, in Euler
    def toQuatFrom(radians: glm.vec3, order: str = 'ZXY', extrinsic: bool = True) -> glm.quat:
AttributeError: module 'glm' has no attribute 'vec3'

EEEE

ERROR: test_euler (unittest.loader._FailedTest)

ImportError: Failed to import test module: test_euler Traceback (most recent call last): File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\unittest\loader.py", line 436, in _find_test_path module = self._get_module_from_name(name) File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\unittest\loader.py", line 377, in _get_module_from_name import(name) File "D:\a\spatial-transform\spatial-transform\SpatialTransform\tests\test_euler.py", line 4, in from SpatialTransform import Euler File "D:\a\spatial-transform\spatial-transform\SpatialTransform__init__.py", line 1, in from .lib.transform import Transform File "D:\a\spatial-transform\spatial-transform\SpatialTransform\lib\transform.py", line 5, in from .euler import Euler File "D:\a\spatial-transform\spatial-transform\SpatialTransform\lib\euler.py", line 8, in class Euler: File "D:\a\spatial-transform\spatial-transform\SpatialTransform\lib\euler.py", line 18, in Euler def toQuatFrom(radians: glm.vec3, order: str = 'ZXY', extrinsic: bool = True) -> glm.quat: AttributeError: module 'glm' has no attribute 'vec3'

Zuzu-Typ commented 1 year ago

Hi there @Wasserwecken,

the issue is that you are using the library "glm" alongside "PyGLM" inside https://github.com/Wasserwecken/spatial-transform/blob/main/requirements.txt . For whatever reason, Python packages distributed over the PyPI do not have to have the same module name. In the case of PyGLM, the package is called PyGLM and contains two modules: "glm" and "glm-stubs". However, the package glm also contains a module called "glm". Thus the python interpreter doesn't know which one to use if you direct it to import glm. In this case, it uses the one from the "glm" package.

It is not currently possible to use the two packages alongside each other (as far as I'm concerned).

Distributing PyGLM this way was a decision I made when I was still very inexperienced with the PyPI and I am contemplating changing the package structure. Then you would have to use the following import command: from PyGLM import glm

Zuzu-Typ commented 1 year ago

I'm assuming you meant to only put PyGLM into your requirements file, so to fix the issue you've mentioned, just remove this line: https://github.com/Wasserwecken/spatial-transform/blob/main/requirements.txt#L1

Wasserwecken commented 1 year ago

Thanks for that lighning fast answer.

Yes this was the error. Removing the 'glm' requirement solves the problem!

The requirements.txt was generated with:

python -m pipreqs.pipreqs --force

Don't know what that glm package is and where it appeard.