简体   繁体   English

在虚拟环境(pyenv)下使用python 3.4.3安装OpenCV3.0

[英]Install OpenCV3.0 with python 3.4.3 under virtual environment (pyenv)

I am struggling trying to install OpenCV 3.0.0 with Python3.4.3 and on a virtual env using pyenv. 我正在努力尝试将OpenCV 3.0.0与Python3.4.3并在使用pyenv的虚拟环境中安装。 I am on Ubuntu 14.04. 我在Ubuntu 14.04上。

I tried many things using various sources of information: http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/ http://www.pyimagesearch.com/2015/06/29/install-opencv-3-0-and-python-3-4-on-osx/ Running OpenCV from a Python virtualenv How to install ipython qtconsole with pyenv (Python version 3.4.2) 我尝试使用各种信息来源很多事情: http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/ HTTP:// www.pyimagesearch.com/2015/06/29/install-opencv-3-0-and-python-3-4-on-osx/ 从Python virtualenv运行OpenCV 如何使用pyenv安装ipython qtconsole(Python版本3.4。 2)

The hard part for me was to link with the correct python from pyenv. 对我而言,最困难的部分是从pyenv链接正确的python。 I have 3.4.3 installed in pyenv with shared libraries (env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.4.3) and a virtualenv called "dev" with numpy installed and working. 我在pyenv中安装了3.4.3,并带有共享库(env PYTHON_CONFIGURE_OPTS =“-enable-shared” pyenv安装3.4.3)和一个名为“ dev”的virtualenv,已安装并运行numpy。

My cmake command is as follow: 我的cmake命令如下:

PREFIX_MAIN=`pyenv virtualenv-prefix`
PREFIX=`pyenv prefix`

cmake -D CMAKE_BUILD_TYPE=RELEASE \
  -D CMAKE_INSTALL_PREFIX="$PREFIX" \
  -D PYTHON3_LIBRARY="$PREFIX_MAIN"/lib/libpython3.4m.so \
  -D PYTHON3_INCLUDE_DIRS="$PREFIX_MAIN"/include/python3.4m \
  -D PYTHON3_EXECUTABLE="$PREFIX"/bin/python3.4 \
  -D PYTHON3_PACKAGES_PATH="$PREFIX"/lib/python3.4/site-packages/ \
  -D PYTHON3_NUMPY_INCLUDE_DIRS="$PREFIX"/lib/python3.4/site-packages/numpy/core/include \
  -D INSTALL_C_EXAMPLES=ON \
  -D INSTALL_PYTHON_EXAMPLES=ON \
  -D BUILD_EXAMPLES=ON \
  -D BUILD_opencv_python3=ON \
  -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..

But cmake still does not want to find the Python 3 Libraires (see cmake output below): 但是cmake仍然不想找到Python 3库(请参见下面的cmake输出):

--   Python 2:
--     Interpreter:                 /home/group/.pyenv/shims/python2.7 (ver 2.7.6)
--
--   Python 3:
--     Interpreter:                 /home/group/.pyenv/versions/dev/bin/python3.4 (ver 3.4.3)
--     Libraries:                   NO
--     numpy:                       /home/group/.pyenv/versions/dev/lib/python3.4/site-packages/numpy/core/include (ver 1.10.0.post2)
--     packages path:               /home/group/.pyenv/versions/dev/lib/python3.4/site-packages
--
--   Python (for build):            /home/group/.pyenv/shims/python2.7

Also it seems it wants to use "/home/group/.pyenv/shims/python2.7" for build. 同样,它似乎也想使用“ /home/group/.pyenv/shims/python2.7”进行构建。 I don't think it is the problem. 我不认为这是问题。

Investigating the cmake ouput I found the following: 调查cmake输出,我发现了以下内容:

-- Found PythonInterp: /home/group/.pyenv/versions/dev/bin/python3.4 (found suitable version "3.4.3", minimum required is "3.4")
-- Could NOT find PythonLibs: Found unsuitable version "3.4.0", but required is exact version "3.4.3" (found /home/group/.pyenv/versions/3.4.3/lib/libpython3.4m.so)

It seems libpython3.4m.so is version 3.4.0.. although I explicitly installed 3.4.3...Could this be the problem? 看来libpython3.4m.so是版本3.4.0 ..,尽管我明确安装了3.4.3 ...这可能是问题吗? How can I get the proper PythonLibs? 如何获得适当的PythonLib?

I have very little experience with these things and I am frankly lost here... 我对这些事情几乎没有经验,坦率地说我在这里迷路了...

EDIT: I have tried to compile with python version 3.4.0 on my pyenv (env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.4.0) and it worked using the cmake commands above. 编辑:我试图在pyenv上使用python 3.4.0版进行编译(env PYTHON_CONFIGURE_OPTS =“-enable-shared” pyenv install 3.4.0),并且使用上面的cmake命令可以正常工作。 Either opencv wants explicitly 3.4.0 either I don't understand how the shared library installed for 3.4.3 are actually seen as 3.4.0... opencv要么明确想要3.4.0,要么我不明白如何为3.4.3安装的共享库实际上被视为3.4.0 ...

EDIT: Same problem with python 2.7.10 under pyenv, you should use 2.7.6... 编辑:在pyenv下使用python 2.7.10的同样问题,您应该使用2.7.6 ...

-- Found PythonInterp: /home/group/.pyenv/versions/cv2/bin/python2.7 (found suitable version "2.7.10", minimum required is "2.7") 
-- Could NOT find PythonLibs: Found unsuitable version "2.7.6", but required is exact version "2.7.10" (found /home/group/.pyenv/versions/2.7.10/lib/libpython2.7.so)

I solved this problem by installing newer version of cmake. 我通过安装较新版本的cmake解决了此问题。 I'm using Ubuntu 14.04 and it seems, that the version of cmake shipped with this Ubuntu doesn't understand newer versions of python. 我正在使用Ubuntu 14.04,似乎该Ubuntu附带的cmake版本不了解python的较新版本。

Ok, solved for me too! 好的,我也解决了!

I have ubuntu 14.04 LTS, anaconda2, and I followed: http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu (without the contrib folder) 我有ubuntu 14.04 LTS,anaconda2,并且我遵循: http : //www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu (没有contrib文件夹)

I constantly hit the "unsuitable version" problem. 我经常遇到“不合适的版本”问题。 What solved for me is downgrading the python to exact version of my python2.7-dev, that is, 2.7.6. 对我来说解决的是将python降级到我的python2.7-dev的确切版本,即2.7.6。

Of course, in my anaconda environment: 当然,在我的anaconda环境中:

conda install python=2.7.6

For now, I don't know how to upgrade the python2.7-dev library to 2.7.11 (and at this point I'm afarid to ask ;) ) 现在,我不知道如何将python2.7-dev库升级到2.7.11(在这一点上,我很想问;))

Probably upgrading cmake to 3.2.2 also helped but it didn't solve the problem by itself. 可能将cmake升级到3.2.2也有所帮助,但它本身并不能解决问题。

Hope it helps! 希望能帮助到你!

ps put in comments how to easily and safely upgrade the python2.7-dev, if you know how. 如果您知道怎么做,ps会发表评论如何轻松,安全地升级python2.7-dev。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM