import problem after adding one line to `sets.py`

31 views
Skip to first unread message

Behrouz Babaki

unread,
Oct 6, 2016, 10:09:05 AM10/6/16
to sympy
Hi
This is the first time that I'm trying to contribute to sympy code.
After adding just one line to `sets.py`, I can not import `sympy` anymore.
This is the line that I added:

from sympy.geometry.point import Point

My guess is that this is caused by a circular import.
What is the right way of dealing with this situation?
- Am I for some reason not supposed to import `Point` into `sets`? or,
- Should I import right in the function where I need to use `Point`? or,
- Are there other parts of the code which need to be refactored? or,
- This does not have anything to do with circular imports?

This is the error that I receive:

>>> import sympy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/__init__.py", line 60, in <module>
    from .polys import *
  File "sympy/polys/__init__.py", line 5, in <module>
    from . import polytools
  File "sympy/polys/polytools.py", line 54, in <module>
    from sympy.polys.domains import FF, QQ, ZZ
  File "sympy/polys/domains/__init__.py", line 9, in <module>
    from . import finitefield
  File "sympy/polys/domains/finitefield.py", line 7, in <module>
    from sympy.polys.domains.groundtypes import SymPyInteger
  File "sympy/polys/domains/groundtypes.py", line 13, in <module>
    from .pythonrational import PythonRational
  File "sympy/polys/domains/pythonrational.py", line 13, in <module>
    from sympy.printing.defaults import DefaultPrinting
  File "sympy/printing/__init__.py", line 8, in <module>
    from .ccode import ccode, print_ccode
  File "sympy/printing/ccode.py", line 21, in <module>
    from sympy.sets.fancysets import Range
  File "sympy/sets/__init__.py", line 1, in <module>
    from .sets import (Set, Interval, Union, EmptySet, FiniteSet, ProductSet,
  File "sympy/sets/sets.py", line 25, in <module>
    from sympy.geometry.point import Point
  File "sympy/geometry/__init__.py", line 13, in <module>
    from sympy.geometry.point import Point, Point2D, Point3D
  File "sympy/geometry/point.py", line 28, in <module>
    from sympy.simplify import nsimplify, simplify
  File "sympy/simplify/__init__.py", line 7, in <module>
    from .simplify import (simplify, hypersimp, hypersimilar,
  File "sympy/simplify/simplify.py", line 15, in <module>
    from sympy.functions import (
  File "sympy/functions/__init__.py", line 8, in <module>
    from sympy.functions.combinatorial.factorials import (factorial, factorial2,
  File "sympy/functions/combinatorial/__init__.py", line 1, in <module>
    from . import factorials
  File "sympy/functions/combinatorial/factorials.py", line 16, in <module>
    from sympy.polys.polytools import poly_from_expr
ImportError: cannot import name poly_from_expr

Björn Dahlgren

unread,
Oct 6, 2016, 5:55:09 PM10/6/16
to sympy


On Thursday, 6 October 2016 16:09:05 UTC+2, Behrouz Babaki wrote:

This is the line that I added:

from sympy.geometry.point import Point



Hi Behrouz,
Sometimes you need to put the import statement in a function body to break to cyclic import, e.g.

def foo(x):
   
from bar.baz import qux
   
return qux(x)



Björn

Reply all
Reply to author
Forward
0 new messages