r/PyPy • • Oct 15 '19

PyPy3 opencv installation

I tried installing opencv in PyPy3 using pypy3 -m pip install opencv-python Didn't work.

How can I install opencv-python? Any help?

2 Upvotes

6 comments sorted by

2

u/extraymond Oct 21 '19 edited Oct 21 '19

Ya! I got it working now.

For anyone wishing to build the package for pypy, here's my procedure.

Prerequisite: Install numpy before opencv-python, it won't try to build it if you already have numpy installed.

  1. Clone the opencv-python repo.

  2. Setup a pypy venv, I created one with pyenv virtual-env pypy3-7.2.0 cv_env

  3. cd into the opencv-python folder

  4. Append CMAKE_ARGS="-D PYTHON3_LIBRARY=~/.pyenv/versions/pypy3.6-7.2.0/lib/libpypy-c.so" before python setup.py bdist_wheel.

The above step is crucial, so make sure it's pointing to the correct libpython equivalent file(libpypy-c.so at the moment). If cmake can't discover the correct python3-library, it will not build and produce the python3 wheel, which is why some users find the following output:

Exception: Not found: 'python/cv2[^/]*\.pypy\72\-x86-64\-linux\-gnu\.so'

If you encounter such error, remember to delete _skbuild folder first, else the cmake options are cached and you will try to build with same config.

Prove that it works: img


TLDR:

pyenv virtualenv pypy3.7.2.0 cv_env
mkdir cv_env
pyenv local cv_env
pip install numpy
git clone https://github.com/skvark/opencv-python
cd opencv-python
CMAKE_ARGS="-D PYTHON3_LIBRARY=~/.pyenv/versions/pypy3.6-7.2.0/lib/libpypy-c.so" python setup.py bdist_wheel
pip install dist/**.wheel

1

u/soyasoya5 Nov 18 '19 edited Nov 18 '19

To add on top of the comment above, for people on Arch and using venv instead of virtualenv, you need to ln -s pypy python3.6 in the /bin folder of your virtual environment. You would also need to add -DPYTHON3_INCLUDE_DIR=/opt/pypy3/include to CMAKE_ARGS since the include folder created by venv is empty.

Furthermore, if contrib modules are built, import cv2 will cause pypy to throw errors and exit, there's an open issue regarding the error.

1

u/Vexellon Feb 25 '20

I can't get this working no matter what I try. I keep getting:

Exception: Not found: 'python/cv2[^/]*\.pypy36\-pp73\-x86_64\-linux\-gnu\.so'

even though I pointed the path of PYTHON3_LIBRARY to my /snap/pypy3/50/bin/libpypy3-c.so

1

u/pmatti Feb 29 '20

u/Vexellon can you paste exactly what you did, and what platform you are on? u/soyasoya5 can you help u/Vexellon out?

1

u/pmatti Oct 15 '19

you would have to clone the repo and try to build it, there are as of yet no binary wheels available. If you make progress, please let us know on IRC at #pypy or a PR/issue in this repo of pypy-specific wheels.

1

u/extraymond Oct 19 '19

I've been trying to get that working for years....

Hope someone shed some light on this.