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

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

Closed
Wasserwecken opened this issue Jan 24, 2023 · 3 comments

Comments

@Wasserwecken
Copy link

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'
  • GitHub CI ubuntu-latest / ubuntu-20.04 / windows-latest
Run python -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 "C:\hostedtoolcache\windows\Python\3.9.[13](https://github.com/Wasserwecken/spatial-transform/actions/runs/3995511510/jobs/6854475050#step:7:14)\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 <module>
    from SpatialTransform import Euler
  File "D:\a\spatial-transform\spatial-transform\SpatialTransform\__init__.py", line 1, in <module>
    from .lib.transform import Transform
  File "D:\a\spatial-transform\spatial-transform\SpatialTransform\lib\transform.py", line 5, in <module>
    from .euler import Euler
  File "D:\a\spatial-transform\spatial-transform\SpatialTransform\lib\euler.py", line 8, in <module>
    class Euler:
  File "D:\a\spatial-transform\spatial-transform\SpatialTransform\lib\euler.py", line [18](https://github.com/Wasserwecken/spatial-transform/actions/runs/3995511510/jobs/6854475050#step:7:19), in Euler
    def toQuatFrom(radians: glm.vec3, order: str = 'ZXY', extrinsic: bool = True) -> glm.quat:
AttributeError: module 'glm' has no attribute 'vec3'
@Zuzu-Typ
Copy link
Owner

Zuzu-Typ commented Jan 24, 2023

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

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

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.

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

2 participants