gammapy / gamma-cat

An open data collection and source catalog for gamma-ray astronomy
https://gamma-cat.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
15 stars 17 forks source link

./makepy check...ImportError: cannot import name 'PowerLaw2' #103

Closed GernotMaier closed 7 years ago

GernotMaier commented 7 years ago

PowerLaw2 seems not to be included in gammapy/spectrum/models.py for the following version:

*** Gammapy version info ***

version: 0.6.dev4426
release: False
githash: 9679fb8d6a98debacd8690cb15c608524661367f

./make.py check
INFO:__main__:Run automated checks ...
INFO:gammacat.checks:Run checks: all
INFO:gammacat.checks:Run checks: input
INFO:gammacat.checks:Reading input data ...
Traceback (most recent call last):
  File "/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/astropy/utils/decorators.py", line 720, in __get__
    return obj.__dict__[self._key]
KeyError: 'input_data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./make.py", line 134, in <module>
    cli()
  File "/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "./make.py", line 89, in make_check
    maker.check_all()
  File "/Users/maierg/Experiments/Gamma/gamma-cat/gammacat/checks.py", line 31, in check_all
    self.check_input()
  File "/Users/maierg/Experiments/Gamma/gamma-cat/gammacat/checks.py", line 37, in check_input
    self.input_data.validate()
  File "/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/astropy/utils/decorators.py", line 722, in __get__
    val = self.fget(obj)
  File "/Users/maierg/Experiments/Gamma/gamma-cat/gammacat/checks.py", line 22, in input_data
    return InputData.read()
  File "/Users/maierg/Experiments/Gamma/gamma-cat/gammacat/input.py", line 334, in read
    from .cat import GammaCatDataSetConfig
  File "/Users/maierg/Experiments/Gamma/gamma-cat/gammacat/cat.py", line 9, in <module>
    from gammapy.spectrum.models import PowerLaw, PowerLaw2, ExponentialCutoffPowerLaw
ImportError: cannot import name 'PowerLaw2'
cdeil commented 7 years ago

@GernotMaier - I think you're importing some old version of gamma-cat from your site-packages.

The PowerLaw2 class is there in master: https://github.com/gammapy/gammapy/blob/master/gammapy/spectrum/models.py#L515

Works for me:

$ python
Python 3.5.3 (default, Jan 21 2017, 15:44:58) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gammapy
>>> gammapy
<module 'gammapy' from '/Users/deil/code/gammapy/gammapy/__init__.py'>
>>> gammapy.__version__
'0.6.dev4427'
>>> from gammapy.spectrum.models import PowerLaw2

@GernotMaier - Can you execute the same code and paste the output here?

Maybe try pip uninstall gammapy a few times until it's gone from your site-packages, and then install the master version and check that you have the latest (should be 0.6.dev4426 I think).

GernotMaier commented 7 years ago

I am really close to giving up installing gammapy....

python
Python 3.4.5 |Anaconda 4.3.1 (x86_64)| (default, Jul  2 2016, 17:47:57)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gammapy
>>> gammapy
<module 'gammapy' from '/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/gammapy/__init__.py'>
>>> gammapy.__version__
'0.4'

It seems that I have three versions installed:

/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/gammapy
/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/gammapy-0.4-py3.4.egg-info/
/Users/maierg/anaconda/envs/python34/lib/python3.4/site-packages/gammapy-0.6.dev4426-py3.4-macosx-10.6-x86_64.egg/

How do I select the version I want to use?

Weird thing is that I get for

$ gammapy-info --version

*** Gammapy version info ***

version: 0.6.dev4426
release: False
githash: 9679fb8d6a98debacd8690cb15c608524661367f
cdeil commented 7 years ago

Try to get rid of the old versions you have in site-packages:

pip uninstall gammapy
conda uninstall gammapy

Then install the dev version.

Note that the gamma-cat scripts won't work with Python 3.4: https://github.com/gammapy/gamma-cat/issues/64#issuecomment-296217378

@GernotMaier - If you just want to do some data entry for gamma-cat, just put the files with the data and I'll fix any formatting or data entry issues.

GernotMaier commented 7 years ago

OK - that worked. Thanks.

I also want to use gammapy, so this was important for me.