问题
I need to install cv2
for a script that has been written for me. I tried pip install cv2
and pip install open_cv
and got the same problem - a warning message from dist.py
and complains about zlib
being not found. No cv2 installed. I also tried pyopenvc
and pip install opencv-python
.
So, I went to the opencv site and downloaded the relevant exe. Ran it - generated a heap of subdirectories and a make file and stuff.
What do I do now?
回答1:
Install opencv-python (which is an unofficial pre-built OpenCV package for Python) by issuing the following command:
pip install opencv-python
Make sure your command prompt has sudo elevated permissions.
回答2:
run the following command by creating a virtual enviroment using python 3 and run
pip3 install opencv-python
to check it has installed correctly run
python3 -c "import cv2"
回答3:
Everybody struggles initially while installing opencv. Opencv requires lot of dependencies in back-end. The best way to start with opencv is, install it in virtual environment. I suggest you to first install python anaconda distribution and create virtual environment using it. Then inside virtual environment using conda install command you can easily install opencv. I feel this is the most safe and easy approach to install opencv. The following command work for me, you can try the same.
conda install -c menpo opencv3
回答4:
Open anaconda command prompt and type in below command.
conda install -c conda-forge opencv
Once the 'Solving environment' is done. It will ask to download dependencies. Type 'y'.
- It will install all the dependencies and then you are ready to code.
回答5:
Make a virtual enviroment using python3
virtualenv env_name --python="python3"
and run the following command
pip3 install opencv-python
to check it has installed correctly run
python3 -c "import cv2"
回答6:
As of OpenCV 2.2.0, the package name for the Python bindings is "cv".The old bindings named "opencv" are not maintained any longer. You might have to adjust your code. See http://opencv.willowgarage.com/wiki/PythonInterface.
The official OpenCV installer does not install the Python bindings into your Python directory. There should be a Python2.7 directory inside your OpenCV 2.2.0 installation directory. Copy the whole Lib folder from OpenCV\Python2.7\ to C:\Python27\ and make sure your OpenCV\bin directory is in the Windows DLL search path.
Alternatively use the opencv-python installers at http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv.
Or Simply install
sudo pip3 install opencv-python #for python3
sudo pip install opencv-python #for python2
回答7:
Simply use this for the so far latest version 4.1.0.
pip install opencv-contrib-python==4.1.0.25
For default version use this:
pip install opencv-contrib-python
回答8:
- Open terminal
- Run the following command
pip install --trusted-host=pypi.org --trusted-host=files.pythonhosted.org opencv-python
. - Hope it will work.
回答9:
As of 10/22/2019, I think the best answer is simply
conda install opencv
It appears opencv
is now in the main Anaconda
channel.
To see which packages (including opencv
) are in the main Anaconda
channel go to Anaconda Package Lists and follow the link corresponding to your python version and os version.
回答10:
There are two options-
pip install cv2
or
pip install opencv-python
Hope it helps.
来源:https://stackoverflow.com/questions/51853018/how-do-i-install-opencv-using-pip