14

我正在尝试在我的 Ubuntu Server 12.04 上的 virtualenv 中安装 OpenCV。我找到了一个讨论这个问题的线程,但没有从中提取任何信息。

我尝试使用pip install pyopencv但失败了。

...
package/extras/core/ndarray.cpp:598:1:   instantiated from here

package/extras/core/ndarray.cpp:546:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘Py_intptr_t {aka long int}’ [-Wformat]

package/extras/core/ndarray.cpp: In function ‘boost::python::api::object sdcpp::from_ndarray_impl(const sdcpp::ndarray&) [with T = cv::Scalar_<double>]’:

package/extras/core/ndarray.cpp:601:1:   instantiated from here

package/extras/core/ndarray.cpp:546:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘Py_intptr_t {aka long int}’ [-Wformat]

package/extras/core/ndarray.cpp: In function ‘boost::python::api::object sdcpp::from_ndarray_impl(const sdcpp::ndarray&) [with T = cv::Range]’:

package/extras/core/ndarray.cpp:604:1:   instantiated from here

package/extras/core/ndarray.cpp:546:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘Py_intptr_t {aka long int}’ [-Wformat]

error: command 'gcc' failed with exit status 1

此错误仅在我第二次运行时发生pip install。如果我删除剩余的build/文件夹,我会收到此错误。

-- Configuring incomplete, errors occurred!

Configuring PyOpenCV via CMake...

Error: error occurred while running CMake to configure PyOpenCV.

You may want to manually configure PyOpenCV by running cmake's tools:

    mkdir build

    cd build

    cmake-gui ..    OR    cmake ..

    cd ..

----------------------------------------
Command python setup.py egg_info failed with error code 255

我至少安装了以下 apt 软件包。

build-essential
uuid-dev
python-dev
python-pip
libpq-dev
cmake
libboost-dev
libcv-dev
libcvaux-dev
libboost-python-dev
libboost1.48-dev

如何在我的 virtualenv 中安装 OpenCV?

4

3 回答 3

13

启动 virtualenv 并遵循本指南: http: //www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/,直到操作和复制 cv 共享对象。相反,我将 cv.so(从我的 OpenCV-2.2.0/lib 目录)复制到了我的 virtualenv 站点包(例如 env/lib/python2.7/site-packages/)。一旦 cv.so 在我的环境中,我就可以在 python 中导入 cv。

于 2012-11-09T20:29:13.230 回答
9

Here is the cleanest way, using pyenv and the virtualenv plug-in.

Install Python with shared library support (so we get a libpython2.7.dylib on Mac OS X or libpython2.7.so on Linux).

env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install -v 2.7.6

Create the virtualenv, based on the version of python we just installed.

pyenv virtualenv 2.7.6 myvirtualenv

Activate the virtualenv.

pyenv shell myvirtualenv
pyenv rehash

Install numpy. Otherwise opencv will fail to link itself to Python correctly.

pip install numpy

Set the prefix of the python install.

PREFIX_MAIN=`pyenv virtualenv-prefix`

Set the prefix of the environment. (sic! The name of these pyenv commands are a bit deceptive!)

PREFIX=`pyenv prefix`

Now configure and install opencv. Notice that the opencv binaries and packages will be installed in our virtualenv while the dynamic library and includes of the Python install is used.

cd openCV2.4
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX="$PREFIX" -DPYTHON_EXECUTABLE="$PREFIX"/bin/python2.7 -DPYTHON_LIBRARY="$PREFIX_MAIN"/lib/libpython2.7.so -DPYTHON_INCLUDE_DIR="$PREFIX_MAIN"/include/python2.7 -DPYTHON_PACKAGES_PATH="$PREFIX"/lib/python2.7/site-packages/ ..
make install

(On OSX, replace libpython2.7.so with libpython2.7.dylib.)

于 2014-06-09T00:14:00.287 回答
0

你已经apt-get build-dep python-opencv?这将安装所有必需的依赖项以从源代码构建它;如果您尝试在虚拟环境中安装它,则需要它。

于 2013-01-27T09:25:42.587 回答