brent timothy saner via plug on 15 May 2020 18:27:16 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Fixing a Python library mismatch


On 5/15/20 20:59, Walt Mankowski via plug wrote:
> Today I discovered that when I try to import numpy I'm getting the
> following error:
> 
> % python
> Python 3.8.2 (default, Apr  9 2020, 20:21:36) 
> [GCC 9.2.1 20191008] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import numpy
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/home/waltman/.pyenv/versions/3.8.2/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
>     from . import core
>   File "/home/waltman/.pyenv/versions/3.8.2/lib/python3.8/site-packages/numpy/core/__init__.py", line 102, in <module>
>     from . import _dtype_ctypes
>   File "/home/waltman/.pyenv/versions/3.8.2/lib/python3.8/site-packages/numpy/core/_dtype_ctypes.py", line 25, in <module>
>     import _ctypes
> ImportError: libffi.so.6: cannot open shared object file: No such file or directory
> 
> This almost certainly broke when I updated to Ubuntu 20.04 a few weeks
> ago. It probably removed libffi.so.6 and replaced it with
> libffi.so.7. I can't figure out how to rebuild numpy with the new
> library. I've tried `pip uninstall numpy; pip install numpy` but that
> didn't have any effect.
> 
> Anyone have any suggestions on how to fix it? I'm using pyenv and pip.
> 
> Walt

three ways to fix:

ONE: the proper, stable way

use numpy and python 3 from the ubuntu repositories. this ensures the
modules and system libraries are always in sync (unless a packager
somewhere made an oopsie).


TWO A: the "i don't like the proper, stable way" way
a.k.a. the "i know better than the distro packagers" way

just recreate your env. i'd recommend using venv rather than pyenv,
though, since it's stdlib in python3.3+
(https://docs.python.org/3/library/venv.html). since it looks like
you're using python3.8, and assuming it's installed system-wide,

python3.8 -m venv some_venv_dir

TWO B: the "fuck that" way

uninstall numpy from your pyenv and reinstall it. as long as it doesn't
keep a build cache, it should build from whatever libffi is available.



THREE: the honeybadger way
a.k.a. the yolo way

this is a hack, but it works 9 times out of 10.

just symlink the lib.

cd /usr/lib64[0]
ln -s libffi.so[1] libffi.so.6


[0] i don't know where ubuntu installs libffi to. it might be /usr/lib/,
etc. "find / -type f -iname "libffi*.so" will find it for you.

[1] libffi.so, if it exists, is probably just a symlink to libffi.so.7.
but it should be okay; you max out at 5 symlink levels. this would be
only 2. you want to symlink to the .so instead of .so.7 directly because
that's always going to point to the newest lib and the link won't break
on package update. if the .so link does NOT exist, just link .so.6 to
.so.7 and remember to update it.



TWO: the proper way

Attachment: signature.asc
Description: OpenPGP digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug