How to install opencv library in python 3.5? - python

I've created a project in Pycharm IDE. I've used python 3.5, tensorflow library. Now I want to install opencv in this.
I have tried so many videos available on youtube and some tutorials in the internet. But when import open cv in python shell it gives me following error. How can I fix it?
import code
import cv2
Error message
Traceback (most recent call last):
File "", line 1, in
import cv2
ImportError: Module use of python27.dll conflicts with this version of Python.
I have noticed that python 2.7 is used to install opencv. Is it a must o use 2.7 version?
Also as I know tensorflow will not support if I use another version of python(other than 3.5)

You can try using
python -m pip install opencv-python
This method uses the unofficial OpenCV PyPi wheels for Linux, Mac and Windows

Did you download open cv for Python 3? Try this:
Make sure you have numpy installed
Download open cv for Python 3 from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
(not sure if this will work with Python 3.5, should work with 3.2)
Run pip install opencv_python-your_verison_here.whl

Since PyCharm is tagged I'm assuming you are wanting to know how to get opencv installed in PyCharm specifically. There is a PyCharm guide for installing packages here.
Step by step would be...
File | Settings | Project:MyProject | Project Interpreter
Click the + symbol on the right
Type opencv-python
Select opencv-python
Click Install Package at the bottom left
Opencv should now be added to PyCharm. You can verify that it is by...
Tools | Python Console...
Clicking in the console window which pops up on the bottom
import cv2

There are a lot of suggestions on how to solve this, but this was actually very easy to solve when using Anaconda. The problem is not the Visual C++ 2015 redistribution, but rather the python3.dll which is missing from
C:\Users\username\AppData\Local\Continuum\Anaconda3 as your second link suggests.
A lot of these sites suggests downloading it manually, but according to this thread ContinuumIO/anaconda-issues#1394 the most recent anaconda packages should all include the missing python3.dll file. So by updating python with conda, this was solved:
**conda update python**

try typing this into your terminal :
pip install opencv_python.
This worked for me.I have Python 3.5.2.

Related

Why I can't import cv2 and other modules to python

I have problem with importing some modules into python.
First of all, I am on MacBook, it's my first OS X device, so maybe I did something wrong.
I installed conda, created main. Everytime I want to work on my python app, I just open terminal, use command: conda activate main, cd into folder and open in VS code. I used pip3 install opencv-python to download this module, It was completed without errors but when I import everything into python file (cv2, tensorflow, matplotlib.pyplot and numpy) and I just
try to print Hello, I get this error:
Traceback (most recent call last):
File "/Users/zacikm/dev/Python/BC/main.py", line 1, in <module>
import cv2 as cv
ModuleNotFoundError: No module named 'cv2'
Please, help me what can I do to fix this problem. I want to start working on my school project but I'm not able.
Thanks!
Sure.
Picture when I run "pip install opencv-python" under conda env.
Error message what I get after running my code.
Check are you using the right environment after installing the pkg pip install opencv-python.
For example, you are using base python rather the conda one.
Say your conda environment is called test.
You need to run
conda activate test
Then use
pip install opencv-python
to re-install it for this environment. Then you can use cv2 in this test environment.
I had the same problem. I found that the solution was to downgrade the opencv version. In Pycharm, the process is as follows:
In Preferences, go to Python interpreter. You will see the current versions of opencv-contrib-python and opencv-python which may be the same as the latest version.
That is the problem.
Double click on the current version of opencv-contrib-python to open this screen:
Check the specify version checkbox and find version 4.1.2.30. Then click Install Package and wait a few seconds to get a message that package was successfully installed. Press OK and you should see opencv-conbtrib-python downgraded to the appropriate version.
After step 3, opencv-python may have also downgraded to the appropriate version 4.2.0.34. If it hasn't, follow the same process to downgrade opencv-python to 4.2.0.34. At the end, your python interpreter screen should look like this:
That should do it. Test it to make sure it works.

problem installing and importing modules in python

I am installing python on windows10 and trying to install the opencv and numpy extentions in the command window. I get no error installing them and it says it is successfully installed. But when I try to check the installation and import cv2 it does not recognize it and give me the error: no module named cv2.
can anybody help me with this problem? Is there something wrong in installation process or do I need to install something else?
I checked the newest version of each and used the compatible one with my system.
Thanks.
One solution could be that you have 2 versions of python. So, go to the specific python's scripts directory and run: pip install numpy
If that too doesn't work, you can find the answers to this question on Why can't I import opencv3 even though the package is installed?, as stated by #Cut7er.
I have tried the solutions given to the above stated question myself also. But, they didn't work for me. So, another thing that you could try to use is this IDE called PyCharm. It ofcourse is much more beautiful that the IDLE, but it also has an inbuilt GUI controlled installation of binaries or packages. That would make things a lot easier. I have faced a lot of issues with packages for python and this IDE made things a lot easier. You can find it on https://www.jetbrains.com/pycharm/download/#section=windows.
You can also use anaconda. But, I found it a little difficult to use since, it has similar issues.
EDIT:
Seems like you are using PyCharm. But, you are installing libraries from your command prompt. So, see the answer to: ImportError: No module named 'bottle' - PyCharm. This answer guides you through how to install a certain library through your PyCharm window itself. So,
1) Go to Files>Settings
2) Search for "Interpreter" from the searching tab. Open the interpreter
3) You can now see a plus sign on the right. A click on it will open up a section on the left.
4) In the searching tab, search for numpy or opencv. Click on whichever module you want to install. And then click on the "install package" button on the bottom left. This will install the package for you.
5) Then click save. And run your file that says import cv/cv2.
This should probably do the trick.
Hope it helps!
Is it possible that you have 2 versions of python on your machine and your native pip is pointing to the other one? (e.g. you pip install opencv which installs opencv for python 2, but you are using python 3). If this is so, then use pip3 install opencv
I removed the Anaconda version on my machine, so I just have python 3.7 installed. I removed the python interpreter(Pycharm) and installed it again and the problem got fixed somehow!
I suspect you have two versions of python and the one you're using doesn't have opencv on it, because pip pointed to the wrong one.
A pragmatic solution assuming you're using the python version with conda is to just use conda to install cv2:
conda install -c menpo opencv
A more careful solution is to figure out how to get the pip that points to the python version you're using. On linux I can check that my pip points to my python like this:
:~$ which python
/home/kpierce/anaconda3/bin/python
:~$ which pip
/home/kpierce/anaconda3/bin/pip
So you see the pip and python versions are associated. On windows I suspect you do an analogous thing on the command line like
where python
where pip
And if they don't match, you might try
where python
where pip3
to see if those match. You need to use the pip that points to the correct python version. You can view the python version by entering the python interpreter and running
import sys
sys.version

Actually opening spyder IDE

I've been trying to follow instructions on here and here to install spyder.
I downloaded the Source Code zip file from the first link because that's what I believe is the dmg installer. I don't know what to do with any of the files in the zip file once I download them though.
I already have pip3 installed so I used the command
pip3 install -U spyder
When I run the commmand
/User/Downloads/spyder-3.2.8/scripts/spyder
I get the error
Traceback (most recent call last):
File "/User/Downloads/spyder-3.2.8/scripts/spyder", line 2, in <module>
from spyder.app import start
ImportError: No module named spyder.app
To my understanding, spyder is supposed to be a python IDE that I am expecting to look something like this
I'm just trying to get the IDE running so that I can write my program within it to help me program easier. The only IDE i've used before is eclipse so maybe I'm not thinking of an IDE the right way, but I'm expecting something kind of like eclipse.
(Spyder maintainer here) I think our installation instructions are quite clear, but I repeat them here for you again:
If you are new to Python or the Scientific Python ecosystem, we strongly recommend you to install and use Anaconda. It comes with Spyder and all its dependencies, along with the most important Python scientific libraries (i.e. Numpy, Pandas, Matplotlib, IPython, etc) in a single, easy to use environment.
After installing Anaconda, you need to open the Anaconda Navigator (using Spotlight) and run Spyder from there. Another option is to open Terminal.app and run spyder or spyder3 there too.
You don't need to have our source code at all to use Spyder because it is installed by Anaconda or pip.
Finally, I don't know what Python version you used to run pip3 install -U spyder, but you should really remove what you installed with it and use Anaconda instead. As we said in our installation instructions too:
We also support pip, but please be aware that pip installations are for advanced users with good knowledge of all Spyder dependencies.
This clearly seems to be not your case.

Unable to import cv2 OpenCV 2.4.13 in python 3.6

import cv2
On executing the above code, it shows the following error.
Error:
Traceback (most recent call last) in
()
----> 1 import cv2
ImportError: DLL load failed: The specified module could not be found.
Unable to import cv2 in python
I have installed OpenCV 2.4.13 and Anaconda3 with python 3.6.4.
OpenCV location:C:\Users\harsh\Anaconda3
Anaconda location:C:\Users\harsh\opencv.
I have also added cv2.pyd in C:\Users\harsh\Anaconda3\Lib\site-packages.
Try pip install opencv-python instead of pip install cv2. Although the name of the package changes, you can still import it as import cv2, It will work.
Have also experienced some issues with OpenCV and Anaconda. Anaconda can fetch only OpenCV 2.4, that might not suit your versions. You should try install OpenCV this way
pip install opencv-python
This can happen if you are using windows 10 N distribution, the N distributions does not come pre installed with windows media feature pack, which is required after OpenCV version 3.4 and onwards.
The preferred solution is to install the feature pack at : https://www.microsoft.com/en-us/software-download/mediafeaturepack
Be careful to choose the version that works with your current version of windows.
If that is not an option, fall back to an earlier version of OpenCV that does not have dll dependencies, you can do that by:pip install opencv-python=3.3.0.9
If the problem still persists try using Dependency walker to find out where specifically your problems stem from and then try fixing them individually.
Since windows rolled out it's N version this problem has been seen at many places, and has many impacts across the windows environment, the fastest way to identify if you have this problem is open youtube in Edge browser, if it says HTML5 media plugin not found, this is the problem.
If the problem still persists feel free to add comments.

How to install module and package in python

I'm trying to start with OpenCV with python. I have experience c# and I have knowledge of c++. However, I feel more comfortable with python instead of c++. I installed OpenCV then python 3.4 in visual studio 2015. At the beginning I've received an error numpy, "Module couldn't be found", thankfully, I resolved it. The I got another error cv2 "Module couldn't be found" I asked an question yesterday, but I think the question has been left away. Anyways, I'm not complaining, but I still need some help please to stat with OpenCV in python.
Installing python 3.4 Successful
Installing numpy Successful
installing matpilotlib Failed
installing cv2 Failed
can anybody help me please thanks a lot.
It's very common to install Python packages through pip today (recursive acronym for pip installs packages). However, this is not that trivial under Windows.
How to install matplotlib:
Try to open a commandline and type in pip install matplotlib. If this does not work, you'll need to do some more work to get pip running. I gave a detailed answere here: Not sure how to fix this Cmd command error?.
How to install OpenCV:
The Python OpenCV DLL must be made for your version of Python and your system architecture (or, to be more specific, the architecture your Python was compiled for).
Download OpenCV for your Python version (2/3)
Try replacing the x64 version with the x86 version
There are a lot of different binaries here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv. Try to get the one exactly matching your Python version and System architecture and install it via pip (cp35 means CPython version 3.5 ect.).
If you have the OpenCV .whl file matching your system configuration, do pip install file.whl.
Hope this helps!
You can install matplotlib using pip (which is already installed on your machine - mentioned in your previous quesiton):
pip install matplotlib
more info:
http://matplotlib.org/faq/installing_faq.html
You may be better off using an package such as pythonxy as a start, e.g. from https://python-xy.github.io/ , instead of installing each single package manually.

Categories

Resources