dtamayo / reboundx

A library for adding additional forces to the REBOUND N-body integration package
GNU General Public License v3.0
80 stars 60 forks source link

python 3.5/3.6/3.7 librebound.cpython-36m-x86_64-linux-gnu.so import error #39

Closed zyrxvo closed 5 years ago

zyrxvo commented 5 years ago

I'm having issues with import reboundx giving OSError: librebound.cpython-35m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory on Linux within a python virtualenv. The commands I'm using are:

virtualenv -p python3 venv source venv/bin/activate pip install rebound reboundx (then start a python session in the virtualenv) python

import rebound
import reboundx

When I run import reboundx I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data_local/zyrxvo/venv/lib/python3.5/site-packages/reboundx/__init__.py", line 13, in <module>
    clibreboundx = cdll.LoadLibrary(pymodulespath + '/../libreboundx' + suffix)
  File "/usr/lib/python3.5/ctypes/__init__.py", line 425, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python3.5/ctypes/__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: librebound.cpython-35m-x86_64-linux-gnu.so: cannot open shared object file: No such file or directory

This example uses Python/3.5.3, but I also get the same issue with Python/3.6 and Python/3.7. It might seem obvious that the errors are different for each version of python giving librebound.cpython-35m-x86_64-linux-gnu.so, librebound.cpython-36m-x86_64-linux-gnu.so, and librebound.cpython-37m-x86_64-linux-gnu.so but I've included copies of all 3 just incase it comes up with a Google search result for those who don't know.

The issue does not appear when the same commands are used in macOS (10.14.6). There was a similar issue brought up before (#26) that was closed April 2018. The previous solution was,

In case anyone runs into similar problems like me... upgrade rebound (not reboundx) to 3.5.13 appears to solve the problem.

However, this solution is outdated.

After digging around, it seems to work if reboundx is installed from a git repo. So if I use a local copy of reboundx and first update it with git pull origin master to git-hash fc75c72e43a27f7a54a98a4c7e5f314182341e88 (Fri Aug 16 11:44:19) and I install it using pip install -e . then everything seems to work.

Even so, this does not always work if a local git repo of rebound is also installed using pip install -e ., but it does always seem to work if rebound is installed with pip install rebound. When installed using pip install rebound the rebound git-hash is 1d360a4bbe951b7826dc4654cd1a820259571fb2 (Thu Aug 15 10:01:27 2019). But the newest git-hash in rebound is currently 74addbcedc64a44541f2e2a0c38ba3bd52c064e4 (Fri Aug 16 09:41:21), so maybe this is a rebound issue and not a reboundx issue. But the error is given on import reboundx so I'm submitting it here.

dtamayo commented 5 years ago

Hey Garett,

Thanks so much for the great testing and detailed write-up! I'm away until Tue but will look into this then. This will help a lot.

dtamayo commented 5 years ago

Hey Garett,

I was able to reproduce your issue on my Ubuntu workstation. The problem was that to install, reboundx needs to figure out where rebound is. It was doing that by importing rebound, but the problem when you pip install rebound reboundx is that importing rebound during that build process imports it from a temporary directory that gets cleaned up at the end. Of course you can pip install them one at a time, but I've added a workaround that I think should work in general.

Could you check that the new version on PyPI (3.0.1) fixes the problem for you (just run the same commands again)?

zyrxvo commented 5 years ago

Hi Dan,

The update you made fixes the problem for me.

When I was testing the bug before the bug would show up when I did pip install rebound reboundx, but it would also show up when I did pip install reboundx (without first installing rebound) as well as when I did pip install rebound followed by pip install reboundx. Either way, in all of these cases it works now. pip install -e . is also working when used for both the most recent rebound and reboundx combinations as well.

Thanks Dan

dtamayo commented 5 years ago

Thank you!