SWIG breaking w/ Python 3.6 front-end?

33 views
Skip to first unread message

Umair Khan

unread,
Nov 22, 2019, 2:04:13 PM11/22/19
to OpenStartracker
Hello, this is Umair Khan from the Portland State Aerospace Society.

I'm trying to get a new front-end up and running in Python 3.6 and I can't seem to get the SWIG wrapper working properly. This may be more of a SWIG question than an OpenStarTracker question but I figured it would be worth asking about here. To try and isolate the problem, I'm trying to first get things working with the base OpenStarTracker code from the master branch.

I changed the Python path in unit_test.sh to point to my Python 3.6 installation and then changed the Python headers in the Makefile in the beast directory to point to the 3.6 version. Then when I ran startracker.py I got the following error message:

Loading config
science_cam_may8_0.05sec_gain40/calibration.txt
Traceback (most recent call last):
  File "startracker.py", line 41, in <module>
    beast.load_config(CONFIGFILE)
AttributeError: module 'beast' has no attribute 'load_config'

It seems that the beast module Python is importing is completely empty. If I comment out the load_config line then the same error shows up with the S_DB = beast.star_db() line. But when I check the beast.py file generated by SWIG, everything's in there as per usual.

When I import beast from an interactive Python 3.6 session and use the inspect module, it shows that the imported module is basically empty. Interestingly, when I try and import beast from an interactive Python 2.7 session (with beast made for Python 2.7), it throws an exception:

Python 2.7.15+ (default, Oct  7 2019, 17:39:04) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import beast
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "beast/__init__.py", line 1, in <module>
    from beast import *
  File "beast/beast.py", line 17, in <module>
    _beast = swig_import_helper()
  File "beast/beast.py", line 16, in swig_import_helper
    return importlib.import_module('_beast')
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named _beast

Not quite sure what's going on here since beast.py seems to have all the functionality needed no matter what version of the Python headers I use. Can anyone shed some light? Thanks.

Best,
Umair

Andrew Tennenbaum

unread,
Nov 24, 2019, 5:57:43 PM11/24/19
to Umair Khan, OpenStartracker
Hmm - so I haven’t actually tested ost with python3, but taking a look at 
http://www.swig.org/Doc1.3/Python.html#Python_python3support it says that there is no support for *FILE typemaps in the python3 version of swig. I wonder if this might have something to do with it?

I’ll poke at it a bit later tonight 

--
You received this message because you are subscribed to the Google Groups "OpenStartracker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openstartrack...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openstartracker/f6bd0dfe-e6f0-472c-8829-a54561cdc1d5%40googlegroups.com.

Andrew Tennenbaum

unread,
Dec 8, 2019, 12:19:20 AM12/8/19
to OpenStartracker
Hi - sorry for the delay. I have found & fixed the problem - it looks like there was a change in Python 3 to disallow implicit relative imports

http://swig.10945.n7.nabble.com/Initialize-a-sub-module-within-a-package-with-SWIG-and-Python-3-td13943.html

I've replaced __init__.py in the beast folder with a symlink to beast.py, and made a few other tweaks to fix the the calibration script.

Everything works the same now under both python 2 and 3. I have also updated the readme with instructions on how to switch back and forth between the two


Umair Khan

unread,
Dec 26, 2019, 1:59:35 AM12/26/19
to OpenStartracker
Hey, sorry for the delay on my end too...finals, then being out of town for a week, then Christmas meant I didn't have a chance to sit down and look at this till now. I initially tried out the master branch of OpenStarTracker and thought it had worked fine because it was giving me a dependency error for Python 3.5 instead of the usual beast error, but returning to it now, I properly set up 3.5 on my laptop and it seems the issue has only been kicked downstream:

Traceback (most recent call last):
  File "/home/ukhan/github/openstartracker/beast/__init__.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 985, in _gcd_import
  File "<frozen importlib._bootstrap>", line 968, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
ImportError: No module named '_beast'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "startracker.py", line 10, in <module>
    import beast
  File "/home/ukhan/github/openstartracker/beast/__init__.py", line 17, in <module>
    _beast = swig_import_helper()
  File "/home/ukhan/github/openstartracker/beast/__init__.py", line 16, in swig_import_helper
    return importlib.import_module('_beast')
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_beast'

Not sure if you ran into this while debugging, still trying to figure out this hurdle. Thanks for your help!

Best,
Umair

Umair Khan

unread,
Jan 1, 2020, 2:49:29 PM1/1/20
to OpenStartracker
Update for future people: update SWIG to 4.0.1 (I was on 3.0.10) fixed this problem.

Best,
Umair
Reply all
Reply to author
Forward
0 new messages