I took a look at what happens when you run import sympy, and it imports all of sympy.
https://github.com/sympy/sympy/blob/master/sympy/__init__.py
If you are only using certain parts of sympy, then only import those parts that you need.
It would be nice if you could do this:
import sympy.sets
But (as you point out) that imports sympy and then sets.
One solution is to write your own importer. You can do this with the help of the imp module.
import imp
sets = imp.load_module("sets", open("sympy/sets/__init__.py"), "sympy/sets/__init__.py", ('.py', 'U', 1))
But, even that may not optimize enough. Taking a look at sympy/sets/__init__.py
I see that it does this:
from .sets import (Set, Interval, Union, EmptySet, FiniteSet, ProductSet,
Intersection, imageset, Complement, SymmetricDifference)
from .fancysets import TransformationSet, ImageSet, Range, ComplexRegion
from .contains import Contains
from .conditionset import ConditionSet
Maybe you can import only the sets module from simpy sets namespace?
import imp
sets = imp.load_module("sets", open("sympy/sets/set.py") "sympy/sets/set.py", ('.py', 'U', 1))