(guest@joequery.me)~ $ |

Resolving libpypy-c.so issues with Pypy and Tox on Ubuntu

While attempting to run unittests with the PyPy Python implementation under the Tox multi-python testing tool, I came across some errors related to the libpypy-c.so shared library that comes with the PyPy binary distribution.

Relevant error messages

error while loading shared libraries: libpypy-c.so: cannot open shared object file: No such file or directory

and

debug: WARNING: Library path not found, using compiled-in sys.path.
debug: WARNING: 'sys.prefix' will not be set.
debug: WARNING: Make sure the pypy binary is kept inside its tree of files.
debug: WARNING: It is ok to create a symlink to it from somewhere else.

My initial setup:

PyPy warns you when compiling from source that the compilation time can take up to two hours, so PyPy highly recommends downloading the binary for your OS instead.

I did a wget on the 32bit tar of the binary for Ubuntu

$ wget "https://bitbucket.org/pypy/pypy/downloads/pypy-2.6.1-linux.tar.bz2"

After untarring the download, this is what the directory structure looked like:

pypy-2.6.1-linux
├── bin
|    ├── libpypy-c.so
|    └── pypy
├── include
├── lib_pypy
├── lib-python
├── LICENSE
├── README.rst
└── site-packages

Error causes: What NOT to do

Do not improperly install PyPy

I initally took the following steps, which ended up not working

  • I copied the pypy executable to /usr/local/bin
  • I copied the libpypy-c.so shared library object to /usr/local/lib
  • I rebuilt the shared library cache via sudo ldconfig
  • I verified the libpypy-c.so shared library was available via sudo ldconfig -v

Solution: What to do

These lines of the error messages were the most helpful:

debug: WARNING: Make sure the pypy binary is kept inside its tree of files.
debug: WARNING: It is ok to create a symlink to it from somewhere else.

The pypy directory (in my case pypy-2.6.1-linux) needs to remain intact instead of just moving the binary onto the execution PATH.

Clean up your dirty installation

If you followed an installation procedure similar to mine above, you should clean it up first.

  1. Delete the pypy binary
  2. Delete the libpypy-c.so file if you moved it to some shared library path
  3. Rebuild the shared library cache via sudo ldconfig

Proper installation

First, ensure the bin directory of your untarred pypy download contains both the pypy executable and libpypy-c.so. They may be missing if you mv'd files from the directory instead of cping them.

Next, relocate the untarred pypy directory.

$ sudo mv pypy-2.6.1-linux /usr/local/pypy

Then I created a symlink to the pypy executable somewhere that was on the PATH.

$ sudo ln -s /usr/local/pypy/bin/pypy /usr/local/bin/

After that, Tox was able to run unit tests for PyPy. You should not need to manually interact with the libpypy-c.so file at all.

Tagged as python, ubuntu

Date published - September 06, 2015