astroML / gatspy

General tools for Astronomical Time Series in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SuperSmoother algorithm cannot be used

dutry opened this issue · comments

Even after I have installed supersmoother via pip and imported it, it cannot be simply used and shows warning:

ImportError: Package supersmoother is required. Use pip install supersmoother to install

This indicates you installed supersmoother using the wrong Python executable.

This StackOverflow answer might help: https://stackoverflow.com/questions/39007571/running-jupyter-with-multiple-python-and-ipython-paths/39022003#39022003

It was in the right place, I checked its place installed, it shows 👍

Name: supersmoother
Version: 0.4
Summary: Python implementation of Friedman's Supersmoother
Home-page: http://github.com/jakevdp/supersmoother
Author: Jake VanderPlas
Author-email: jakevdp@uw.edu
License: BSD 3-clause
Location: /usr/local/anaconda3/lib/python3.7/site-packages

It's right at the same place as astropy, while I can use astropy.

If you can't import it, it's not installed in the right place.

I have fixed the problem.

I found that in everywhere else I can import supersmoother, except for in the directory /usr/local/anaconda3/lib/python3.7/site-packages/gatspy/periodic, i.e. the directory where supersmoother.py from Gatspy located. If I try to import supersmoother here, it returns error:

>>> import supersmoother
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/anaconda3/lib/python3.7/site-packages/gatspy/periodic/supersmoother.py", line 24, in <module>
    from .modeler import PeriodicModeler, PeriodicModelerMultiband
ImportError: attempted relative import with no known parent package

It tries to import the supersmoother right here, from the Gatspy package, that's why it fails.

So I have to add an absolute path for the supersmoother to be imported, I added such code in the beginning of the gatspy/periodic/supersmoother.py:

MODULE_PATH = "/usr/local/anaconda3/lib/python3.7/site-packages/supersmoother/__init__.py"
MODULE_NAME = "supersmoother"
import importlib
import sys
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module                                             
spec.loader.exec_module(module)

Then all will work well.

I think maybe the file supersmoother.py should not be named as the same name of a package.