# How install opencv to a venv python3 dist-packages?

**URL:** <https://forum.opencv.org/t/how-install-opencv-to-a-venv-python3-dist-packages/7092>\
**Category:** Python\
**Tags:** build, cmake\
**Created:** [January 11, 2022, 11:41pm UTC](https://forum.opencv.org/t/how-install-opencv-to-a-venv-python3-dist-packages/7092 "2022-01-11T23:41:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stuart\_Reynolds](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/stuart_reynolds/32/4079_2.png) [@Stuart\_Reynolds](https://forum.opencv.org/u/Stuart_Reynolds)\
**Post date:** [January 11, 2022, 11:41pm UTC](https://forum.opencv.org/t/how-install-opencv-to-a-venv-python3-dist-packages/7092/1 "2022-01-11T23:41:57Z")

</div>

With …

```auto
cd opencv/build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
     -D CMAKE_INSTALL_PREFIX=/usr/local \
     -D INSTALL_PYTHON_EXAMPLES=ON \
     -D INSTALL_C_EXAMPLES=OFF \
     -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
     -D OPENCV_GENERATE_PKGCONFIG=ON \
     -D BUILD_EXAMPLES=ON \
     -D PYTHON3_EXECUTABLE=/usr/bin/python3 \
     -D PYTHON3_INCLUDE_DIR=/usr/include/python3.7 \
     -D PYTHON3_INCLUDE_PATH=/usr/include/python3.7 \
     -D PYTHON3_LIBRARIES=/usr/lib/x86_64-linux-gnu/libpython3.7 \
     -D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.7 \
     -D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.7/dist-packages/numpy/core/include \
     -D OPENCV_PYTHON_INSTALL_PATH_SETUPVARS=lib/python3.7/dist-packages \
     ..

```

… I’m told that the install path with still be python 3.6:

```auto
-- 
-- OpenCL: YES (no extra features)
-- Include path: /home/sir/opencv/3rdparty/include/opencl/1.2
-- Link libraries: Dynamic load
-- 
-- Python 3:
-- Interpreter: /home/sir/venv/p37_default/bin/python3 (ver 3.6.9)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.7 (ver 3.6.9)
-- numpy: /usr/local/lib/python3.7/dist-packages/numpy/core/include (ver 1.16.1)
>>> @!!! Eh... Wut?! 3.6 Should be 3.7
-- install path: lib/python3.6/dist-packages/cv2/python-3.6
-- 
-- Python (for build): /home/sir/venv/p37_default/bin/python
-- 
-- Java:                          
-- ant: NO
-- JNI: /usr/lib/jvm/java-8-oracle/include /usr/lib/jvm/java-8-oracle/include/linux /usr/lib/jvm/java-8-oracle/include
-- Java wrappers: NO
-- Java tests: NO
-- 
-- Install to: /usr/local
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/sir/opencv/build

```

How can I target the install at a venv dist-packages directory?

Many references suggest simply copying the .so into the dist\_packages/cv2 directory.

```auto
cp ../build/lib/python3/cv2.cpython-37m-x86_64-linux-gnu.so ~/venv/p37_default/lib/python3.7/site-packages/cv2/

```

However this leaves me with:

```auto
  File "/home/sir/Dropbox/software/vision_noodle/util.py", line 13, in <module>
    import cv2
  File "/home/sir/venv/p37_default/lib/python3.7/site-packages/cv2/ __init__.py", line 5, in <module>
    from .cv2 import *
ImportError: /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5: symbol _ZNK11QLocaleData13validateCharsERK7QStringNS_10NumberModeEP10QByteArrayi6QFlagsIN7QLocale12NumberOptionEE version Qt_5 not defined in file libQt5Core.so.5 with link time reference

```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [January 12, 2022, 7:55am UTC](https://forum.opencv.org/t/how-install-opencv-to-a-venv-python3-dist-packages/7092/2 "2022-01-12T07:55:15Z")

</div>

sounds broken, I agree.

are there any remains of a previous build, e.g. a cmakecache.txt? are there any environment variables that point to a python 3.6?

---

<div class="post-metadata">

**Author:** ![Stuart\_Reynolds](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/stuart_reynolds/32/4079_2.png) [@Stuart\_Reynolds](https://forum.opencv.org/u/Stuart_Reynolds)\
**Post date:** [January 12, 2022, 7:27pm UTC](https://forum.opencv.org/t/how-install-opencv-to-a-venv-python3-dist-packages/7092/3 "2022-01-12T19:27:28Z")

</div>

Environment vars - no, but there did seem to be an issue with state.  
Blowing away the build directory produced the right options _except_ the summary showed:

```auto
   -- Python (for build): /home/sir/venv/p37_default/bin/python

```

as the system python 2.7. Overriding PYTHON\_DEFAULT\_EXECUTABLE (which I found via `grep 2.7 CMakeVars.txt `  
seemed to fix the summary:

```auto
cd ~/opencv
rm -rf ~/opencv/build
mkdir ~/opencv/build
cd ~/opencv/build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
     -D CMAKE_INSTALL_PREFIX=/usr/local \
     -D INSTALL_PYTHON_EXAMPLES=ON \
     -D INSTALL_C_EXAMPLES=OFF \
     -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
     -D OPENCV_GENERATE_PKGCONFIG=ON \
     -D BUILD_NEW_PYTHON_SUPPORT=ON \
     -D BUILD_EXAMPLES=ON \
     -D PYTHON3_INCLUDE_DIR=/usr/include/python3.7 \
     -D PYTHON3_INCLUDE_PATH=/usr/include/python3.7 \
     -D PYTHON3_EXECUTABLE=`which python` \
     -D PYTHON_DEFAULT_EXECUTABLE=`which python` \
     ..
make -j8
sudo make install >& log.txt

```

Installs to the site python:

```auto
-- Installing: /usr/local/lib/python3.7/site-packages/cv2/python-3.7/cv2.cpython-37m-x86_64-linux-gnu.so

```

… which I’m a little confused about since python-3.7 doesn’t appear in `build/CMakeVars.txt`.
