问题
I want to use pypy for better Python performance. I installed pypy via snap on Ubuntu 18.04. I am now able to use pypy in virtualenv (Actually pipenv is what I'm using)
Trying to compile opencv-python for pypy3 in a virtualenv from git repo by:
git clone https://github.com/skvark/opencv-python.git
python setup.py install
and getting:
Exception: Not found: 'python/cv2[^/]*\.pypy36\-pp73\-x86_64\-linux\-gnu\.so'
I found this post which suggests:
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
So I cloned the repo and tried to run:
CMAKE_ARGS="-D PYTHON3_LIBRARY=/snap/pypy3/50/bin/libpypy3-c.so" python setup.py bdist_wheel
I get:
CMake Error: The source directory "/home/user/Projects/project1_pypy/pypy/opencv-python/_skbuild/linux-x86_64-3.6/cmake-build/PYTHON3_LIBRARY=/snap/pypy3/50/bin/libpypy3-c.so" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
Traceback (most recent call last):
File "/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/site-packages/skbuild/setuptools_wrap.py", line 574, in setup
languages=cmake_languages
File "/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/site-packages/skbuild/cmaker.py", line 232, in configure
os.path.abspath(CMAKE_BUILD_DIR())))
An error occurred while configuring with CMake.
Command:
"cmake" "/home/user/Projects/project1_pypy/pypy/opencv-python/opencv" "-G" "Unix Makefiles" "-DCMAKE_INSTALL_PREFIX:PATH=/home/user/Projects/project1_pypy/pypy/opencv-python/_skbuild/linux-x86_64-3.6/cmake-install" "-DPYTHON_EXECUTABLE:FILEPATH=/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/bin/python" "-DPYTHON_VERSION_STRING:STRING=3.6.9" "-DPYTHON_INCLUDE_DIR:PATH=/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/include" "-DPYTHON_LIBRARY:FILEPATH=" "-DSKBUILD:BOOL=TRUE" "-DCMAKE_MODULE_PATH:PATH=/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/site-packages/skbuild/resources/cmake" "-DPYTHON3_EXECUTABLE=/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/bin/python" "-DBUILD_opencv_python3=ON" "-DOPENCV_SKIP_PYTHON_LOADER=ON" "-DOPENCV_PYTHON3_INSTALL_PATH=python" "-DINSTALL_CREATE_DISTRIB=ON" "-DBUILD_opencv_apps=OFF" "-DBUILD_SHARED_LIBS=OFF" "-DBUILD_TESTS=OFF" "-DBUILD_PERF_TESTS=OFF" "-DBUILD_DOCS=OFF" "-DWITH_QT=4" "-DWITH_V4L=ON" "-DENABLE_PRECOMPILED_HEADERS=OFF" "-DWITH_IPP=OFF" "-D" "PYTHON3_LIBRARY=/snap/pypy3/50/bin/libpypy3-c.so" "-DCMAKE_BUILD_TYPE:STRING=Release"
So I tried editing setup.py
and adding under if os.name == 'nt' else [
:
"-DPYTHON_LIBRARY=/snap/pypy3/50/bin/libpypy3-c.so",
It seems like it's about to finish compiling and then I get the same error as before: Exception: Not found: 'python/cv2[^/]*\.pypy36\-pp73\-x86_64\-linux\-gnu\.so'
Am I not passing the compile argument properly? How can I set this path variable properly? It's obviously concatenating these two paths to form the erroneous: CMake Error: The source directory "/home/user/Projects/project1_pypy/pypy/opencv-python/_skbuild/linux-x86_64-3.6/cmake-build/PYTHON3_LIBRARY=/snap/pypy3/50/bin/libpypy3-c.so" does not exist.
Edit:
By the error output, it shows me the compile command:
"cmake" "/home/user/Projects/project1_pypy/pypy/opencv-python/opencv" "-DPYTHON_LIBRARY=/snap/pypy3/50/bin/libpypy3-c.so" "-G" "Unix Makefiles" "-DCMAKE_INSTALL_PREFIX:PATH=/home/user/Projects/project1_pypy/pypy/opencv-python/_skbuild/linux-x86_64-3.6/cmake-install" "-DPYTHON_EXECUTABLE:FILEPATH=/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/bin/python" "-DPYTHON_VERSION_STRING:STRING=3.6.9" "-DPYTHON_INCLUDE_DIR:PATH=/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/include" "-DPYTHON_LIBRARY:FILEPATH=" "-DSKBUILD:BOOL=TRUE" "-DCMAKE_MODULE_PATH:PATH=/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/site-packages/skbuild/resources/cmake" "-DPYTHON3_EXECUTABLE=/home/user/.local/share/virtualenvs/project1_pypy-5DRSQTA5/bin/python" "-DBUILD_opencv_python3=ON" "-DOPENCV_SKIP_PYTHON_LOADER=ON" "-DOPENCV_PYTHON3_INSTALL_PATH=python" "-DINSTALL_CREATE_DISTRIB=ON" "-DBUILD_opencv_apps=OFF" "-DBUILD_SHARED_LIBS=OFF" "-DBUILD_TESTS=OFF" "-DBUILD_PERF_TESTS=OFF" "-DBUILD_DOCS=OFF" "-DWITH_QT=4" "-DWITH_V4L=ON" "-DENABLE_PRECOMPILED_HEADERS=OFF" "-DWITH_IPP=OFF" "-DCMAKE_BUILD_TYPE:STRING=Release"
but that doesn't seem to fully compile the module. hrm. I don't get why adding the arg to setup.py didn't work.
Answer should illustrate fix for compiling opencv-python for pypy3
回答1:
libc
version in /snap/core/current/lib/x86_64-linux-gnu/
is different from the system. You build numpy using system libc and the build system uses snap libc. You can delete _skbuild folder and run setup.py to see the error message ( It doesn't show with cache ). Use PyPy installed from PPA solves the problem.
回答2:
The correct recipe is here. Upvote it if you like it :)
来源:https://stackoverflow.com/questions/60386499/compile-opencv-python-for-pypy3