Search code examples
pythonmatplotlibimporterror

'_cext' - no such module when importing OrbitalPy


I'm using the OrbitalPy lib to display orbits in Python.

However, when I run the program (which is actually listed in the docs/examples of OrbitalPy):

from numpy import radians
from scipy.constants import kilo

from orbital import earth, KeplerianElements, Maneuver, plot, plot3d

from orbital import earth_sidereal_day
molniya = KeplerianElements.with_period(
    earth_sidereal_day / 2, e=0.741, i=radians(63.4), arg_pe=radians(270),
    body=earth)

plot3d(molniya)

I get the following errors:

C:\Users\xxx\Desktop>py molniya.py
Traceback (most recent call last):
  File "C:\Users\xxx\Desktop\molniya.py", line 4, in <module>
    from orbital import earth, KeplerianElements, Maneuver, plot, plot3d
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\orbital\__init__.py", line 8, in <module>
    from .plotting import *
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\orbital\plotting.py", line 9, in <module>
    import matplotlib as mpl
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\__init__.py", line 246, in <module>
    _check_versions()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\matplotlib\__init__.py", line 240, in _check_versions
    module = importlib.import_module(modname)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\kiwisolver\__init__.py", line 8, in <module>
    from ._cext import (
ImportError: DLL load failed while importing _cext: The specified module could not be found.

I already tried reinstalling matplotlib and kiwisolver, but nothing helped. Even a google search didn't give me any results for this issue.


Solution

  • I had the same problem.

    the solution is found on this question:

    Matplotlib kiwisolver import problem _cext

    The solution is just to run:

    pip install msvc-runtime