ajhynes7/scikit-spatial

NameError: name 'Vector' is not defined

Xieyuan0018 opened this issue · 3 comments

  1. When I import normally using "from skspatial.objects import Plane" it will raise SyntaxError: future feature annotations is not defined:
    Traceback (most recent call last):
    File "", line 971, in _find_and_load
    File "", line 955, in _find_and_load_unlocked
    File "", line 665, in _load_unlocked
    File "", line 678, in exec_module
    File "", line 219, in _call_with_frames_removed
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/init.py", line 3, in
    from skspatial.objects.circle import Circle
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/circle.py", line 11, in
    from skspatial.objects._base_sphere import _BaseSphere
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/_base_sphere.py", line 10, in
    from skspatial.objects.point import Point
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/point.py", line 8, in
    from skspatial.objects.vector import Vector
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/vector.py", line 3
    from future import annotations
    ^
    SyntaxError: future feature annotations is not defined

I searched and found that future import is only enabled after python version 3.7 whereas mine is 3.6.6

  1. Then I tried to comment the line which is exist only in vector.py "from future import annotations", it raises error NameError: name 'Vector' is not defined:
    Traceback (most recent call last):
    File "", line 971, in _find_and_load
    File "", line 955, in _find_and_load_unlocked
    File "", line 665, in _load_unlocked
    File "", line 678, in exec_module
    File "", line 219, in _call_with_frames_removed
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/init.py", line 3, in
    from skspatial.objects.circle import Circle
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/circle.py", line 11, in
    from skspatial.objects._base_sphere import _BaseSphere
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/_base_sphere.py", line 10, in
    from skspatial.objects.point import Point
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/point.py", line 8, in
    from skspatial.objects.vector import Vector
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/vector.py", line 18, in
    class Vector(_BaseArray1D):
    File "/home/user/miniconda3/envs/nestinet/lib/python3.6/site-packages/skspatial/objects/vector.py", line 74, in Vector
    def from_points(cls, point_a: array_like, point_b: array_like) -> Vector:
    NameError: name 'Vector' is not defined
    python-BaseException

Please help resolve the issue. Thanks!

Hi @Xieyuan0018,

This occurs because of the type annotations. Python 3.6 doesn't support referring to types in the same class, e.g., you can't have an annotation of Vector in a method of the Vector class.

A workaround is to surround the type annotations with quotes. Since it's only the type annotations that keep this package from working with Python 3.6, I think I can make a new release that supports it.

Hi @Xieyuan0018,

This occurs because of the type annotations. Python 3.6 doesn't support referring to types in the same class, e.g., you can't have an annotation of Vector in a method of the Vector class.

A workaround is to surround the type annotations with quotes. Since it's only the type annotations that keep this package from working with Python 3.6, I think I can make a new release that supports it.

Hi, I tried to quote all the type annotations and it worked :)

Hi @Xieyuan0018,

The new release (5.1.0) is compatible with Python 3.6.