Skip to content

[Question] Complete opencv installation using pip #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
another-guy opened this issue Aug 7, 2016 · 19 comments
Closed

[Question] Complete opencv installation using pip #7

another-guy opened this issue Aug 7, 2016 · 19 comments

Comments

@another-guy
Copy link

Hello Olli-Pekka,

First of all I must say thank you for starting this repository. I am very new to both Python and OpenCV.
I'm trying to start a new project that will intensively use OpenCV. Could you please clarify whether it is possible or not to have a complete OpenCV installation entirely based on pip or easy_install packages? If yes, than what are the steps I should follow.

Drawing a parallel with .NET/Java, I'd like to introduce a single dependency on NuGet/Maven package of OpenCV. In my scenario, development is going to be all in Python, though.

I understand, this question does not really belong here but I can't find a better place and more knowledgeable person to get it answered.

Thanks!

@skvark
Copy link
Member

skvark commented Aug 7, 2016

Do you mean by "complete installation" the Python bindings?

Currently there is no pre-built packages for the OpenCV Python bindings on PyPI (=Python package index), but the aim of this repository is to provide them when we get all the builds stable (Linux and Windows are just about ready, but OS X needs more work). I have been very busy lately, but I'm going to focus more on this during next week so the packages should be available on PyPI soon.

In practice this means that when we are ready to push all of these wheels (=python's pre-built packages) to PyPI, one could simply install the OpenCV package with following command:

pip install opencv-python

and use it with the following import statement:

import cv2

If your project is simple, then you could just add the opencv-python dependency to your setup.py file. However, I recommend to use requirements.txt file for defining the dependencies if your project depends on many packages.

If you're using Windows, you can already install the opencv-python package manually by downloading a package from Appveyor https://ci.appveyor.com/project/skvark/opencv-python/build/artifacts and installing it with pip:

pip install name_of_the_wheel_file.whl

@another-guy
Copy link
Author

another-guy commented Aug 7, 2016

Do you mean by "complete installation" the Python bindings?

I feel very badly about not being able to formulate my question properly due to lack of Python terminology knowledge. Basically, I mean, I'm looking for a "ready to go" Python package that I can refer in my project. I expect this to result in my code downloading OpenCV as a dependency regardless of the platform it runs on, i.e. platform specific binaries.
Again, I don't even know whether it is achievable because I don't know much about packaging in Python world.

pip install opencv-python

This seems to be the way to go but it won't work in windows for me:

$ pip install opencv-python
Collecting opencv-python
  Could not find a version that satisfies the requirement opencv-python (from versions: )
No matching distribution found for opencv-python

If you're using Windows, you can already install the opencv-python package manually by downloading a package from Appveyor

Manual installation is exactly what I am trying to avoid. :)

Offtopic: I'd really appreciate you pointing me to documents that explain Python packaging so that I'm not asking stupid questions in stupid forms anymore. 😞

@skvark
Copy link
Member

skvark commented Aug 7, 2016

I feel very badly about not being able to formulate my question properly due to lack of Python terminology knowledge. Basically, I mean, I'm looking for a "ready to go" Python package that I can refer in my project. I expect this to result in my code downloading OpenCV as a dependency regardless of the platform it runs on, i.e. platform specific binaries.
Again, I don't even know whether it is achievable because I don't know much about packaging in Python world.

It's not a problem :) Python's packaging is currently a bit complicated: there are many ways to do it, but most of them are legacy. You can read more about the packaging from here: https://packaging.python.org/

In brief, this repository is simply just a bunch of automated build scripts (meant to be run on CI systems like Travis and Appveyor) which will compile OpenCV and embed it to a python wheel package. During the compilation the C++ code is wrapped in a special python compatible way (http://docs.opencv.org/3.1.0/da/d49/tutorial_py_bindings_basics.html#gsc.tab=0). The end result is shared library which is then copied to the actual Python package and can be imported with python.

This process is repeated multiple times for every platform (this is not a so called universal package due to an binary extension) and all the results will be uploaded to PyPI (in the future). For example, you can have a look at numpy and observe the many different .whl files for different platforms: https://pypi.python.org/pypi/numpy

pip install will then select the correct package from all the listed packages according to the platform on which it was run. In this case manual installation is needed before we start uploading opencv-python wheels to PyPI. And for the record, these "wheels" are just zip files :)

@another-guy
Copy link
Author

@skvark Thanks! Your intro is helpful! I don't think there's need in keeping this issue open. (btw, windows installation of wheel did actually work for me).

Olli-Pekka, is there a way for me to contact you directly regarding OpenCV or Python? I have 10 years of experience with .NET/Java and would love to be able to ramp up with Python quickly. Considering the style and structure of your explanatory messages, I believe you can be very helpful as a mentor for me. So, if you have time and are willing to I'd write you questions time to time. Let me know.

@skvark
Copy link
Member

skvark commented Aug 8, 2016

You can contact me for example via Twitter, I'll share my email address privately.

@spencerahill
Copy link

Sorry if this should be painfully obvious already, but I am still in need of clarification. Let's suppose I am on a machine on which openCV has not been installed. Will pip install opencv-python install opencv itself as well as the python bindings that are accessible within python via import cv2? Or does openCV itself need to be installed separately? Thanks.

@skvark
Copy link
Member

skvark commented Jan 9, 2017

pip install opencv-python will install only the Python bindings but you do not need additional installations to use the bindings. This opencv-python package contains the special Python compatible OpenCV.

In practice this means that pretty much the whole OpenCV API is available via Python by importing cv2 after pip install has finished. OpenCV official docs have extensive tutorials on how to use the bindings, e.g http://docs.opencv.org/3.2.0/d3/df2/tutorial_py_basic_ops.html (http://docs.opencv.org/3.2.0/d6/d00/tutorial_py_root.html).

If you want to use OpenCV for example via C++ or some other language, then you have to install the whole official package from here: https://github.com/opencv/opencv/releases

If you are interested in how the bindings are generated, have a look at this: http://docs.opencv.org/3.2.0/da/d49/tutorial_py_bindings_basics.html

@spencerahill
Copy link

@skvark thanks, that helps a lot. So, in other words, as long as the user only needs to interact with opencv through python, then pip install opencv-python gets them everything they need.

Given that the full opencv build is not trivial, that's a nice accomplishment!

@skvark
Copy link
Member

skvark commented Jan 9, 2017

Yes, that's correct. Please note that #14 and #17 may block some use cases (stuff related to video i/o and showing gui windows) on Linux / macOS.

And thanks! 😃

@spencerahill
Copy link

Great. It might be worth making this point more clearly in your documentation. I am new to opencv but I am otherwise not a novice, yet I still had this confusion. All the more so because the documentation of opencv itself (to me) is extremely haphazard.

Anyways, thanks again!

@skvark
Copy link
Member

skvark commented Jan 9, 2017

I'll update the readme file.

@shaikhrahil
Copy link

@ skvark , I get the following error on giving pip install opencv-python on my pi zero. Any suggestions

import cv2
Traceback (most recent call last):
File "", line 1, in
File "/home/pi/.local/lib/python3.5/site-packages/cv2/init.py", line 4, in
from .cv2 import *
ImportError: libImath-2_2.so.12: cannot open shared object file: No such file or directory

@skvark
Copy link
Member

skvark commented Apr 23, 2018

I'm sorry, this repository does not provide pre-built wheels for ARM-based platforms. You should contact the person who has created the wheels you are using.

@shaikhrahil
Copy link

Alright , thanks for the quick reply @skvark !!

@abdur12345
Copy link

abdur12345 commented Jul 21, 2018

i have error in my command prompt when i want to install opencv opencv-3.4.2-vc14_vc15.
when i type pip3 install opencv-python or
type pip install opencv-python and there is writing error
"Could not find a version that satisfies the requirement opencv-contrib-python (from versions: )
No matching distribution found for opencv-contrib-python"

@ZLCHEN007
Copy link

@ skvark could you assist below:

>>> import cv2 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: /usr/local/lib/python3.6/site-packages/cv2.cpython-36m-aarch64-linux-gnu.so: undefined symbol: _Z11pyopencv_toIjEbP7_objectRT_PKc

@skvark
Copy link
Member

skvark commented Sep 2, 2018

This is not a Q&A forum and the question you're asking is not even related to this repository. Ask your question at Stack Overflow.

@Hooman08
Copy link

@skvark Hi, obviously I'm new to these problems but I have a weird problem.
I'm using mac os and using mac terminal, I installed opencv and even I saw it's version and I was able to import cv2 but I wonder why I'm not able to install cv2 in pycharm?
I tried but pycharm give me this error: ( Could not find a version that satisfies the requirement cv2 (from versions:
No matching distribution found for cv2)
and it also says "you are using pip version 10.0.1 however version 18.0 is available"
It's really ridiculous because I updated pip to version 18 but apparently pycharm doesn't understand ...

@skvark
Copy link
Member

skvark commented Sep 18, 2018

The name of this package is opencv-python, not cv2. Please read the installation instructions in the README: https://github.com/skvark/opencv-python#installation-and-usage

Ask your question at Stack Overflow. This is a issue tracker, not a Q&A forum.

@opencv opencv locked as off-topic and limited conversation to collaborators Sep 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants