mattkjames7 / PyGeopack

Wrapper for geopack-08 used for the Tsyganenko magnetic field models
GNU General Public License v3.0
11 stars 2 forks source link

Cannot import package #1

Closed TeriForey closed 4 years ago

TeriForey commented 4 years ago

Hi @mattkjames7

I've installed PyGeopack into my virtual environment (created with conda, running python 3.7) and it seems to have installed correctly. However, when I try to import the package I get the following error:

>>> import PyGeopack
Data file does not exist - to create data file run "PyGeopack.UpdateParameters()"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda/envs/SMILE_dev/lib/python3.7/site-packages/PyGeopack/__init__.py", line 3, in <module>
    _CheckFirstImport()
  File "/anaconda/envs/SMILE_dev/lib/python3.7/site-packages/PyGeopack/_CheckFirstImport.py", line 37, in _CheckFirstImport
    from ._CFunctions import _CInit
  File "/anaconda/envs/SMILE_dev/lib/python3.7/site-packages/PyGeopack/_CFunctions.py", line 8, in <module>
    libgeopack = ct.CDLL(os.path.dirname(__file__)+"/__data/libgeopackdp/libgeopackdp.so")
  File "/anaconda/envs/SMILE_dev/lib/python3.7/ctypes/__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/anaconda/envs/SMILE_dev/lib/python3.7/site-packages/PyGeopack/__data/libgeopackdp/libgeopackdp.so, 6): no suitable image found.  Did find:
    /anaconda/envs/SMILE_dev/lib/python3.7/site-packages/PyGeopack/__data/libgeopackdp/libgeopackdp.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
    /anaconda/envs/SMILE_dev/lib/python3.7/site-packages/PyGeopack/__data/libgeopackdp/libgeopackdp.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00

And PyGeopack doesn't import. The file libgeopackdp.so is in the right directory, but it seems to be unable to read it.

I'm working on OSX, which I know can affect some shared library files - is this the case here?

I set the environment variables to three locations within my working directory - do they need to point to the directory that pygeopack is installed into?

mattkjames7 commented 4 years ago

Hi TeriForey,

I'm sorry about this, I suspect that the problem might be due to using the package on OSX (I don't have a Mac to test this on unfortunately). Recompiling it might fix it - is there anyway you could navigate to the directory /anaconda/envs/SMILE_dev/lib/python3.7/site-packages/PyGeopack/__data/libgeopackdp/ and run make clean && make?

Also, are you using version 0.2.2? There was a bug in 0.2.1 where I switched to double precision code but forgot to update the MANIFEST.in file.

Please let me know if recompiling works, or if you have any other problems!

Cheers, Matt.

TeriForey commented 4 years ago

Hi Matt,

Thanks for the help, that worked! I had an intermediate error with missing libgfortran 3, but after installing that into my conda environment and re-running make it seems to be working fine.

As a follow-up question, can I ask why kpindex and pyomnidata aren't required at install? I was unable to run updateParameters() without installing them.

mattkjames7 commented 4 years ago

Hi Teri,

I'm glad that worked, at some point I will see if I can change this package such that the C/Fortran stuff is either compiled on install or first import (this used to be the case, but it had issues when uninstalling/upgrading).

The reason I didn't include them as dependencies is because I figured that not everyone would require them - UpdateParameters() takes ages to run because it downloads all of the OMNI and Kp index data, and it is able to perform traces using either custom parameters or defaults (Pdyn = 2, Dst = 0, By = 0, Bz =0 , -V = Vx = 400.0) without any of those stored values.

I notice that you are from UoL and I'm guessing that you have access to ALICE/SPECTRE - do you have read access to /data/sol-ionosphere ? If so, I can email you a path to set which has all of this ready to use.