ImportError: No module named cv2 after install VS2017 - python

Before:
Install VS2015.
Install opencv 3.2.0.
Now, i install VS2017 and create python project with the following code:
import cv2
When I run it, compiler show the error: "ImportError: No module named cv2"
How to update some libraries - which i installed before - as opencv, numpy,... for VS2017?
Thanks!
UPDATE 1
I knew the reason. Because when i installed VS2017, i also installed other version of Python. VS2017 used the wrong version (it does not have opencv library). And then i created new universal windows python project, VS2017 auto generate PythonUwpIoT (python 3.5 - i don't know and how to have it).

Related

Newer version of python cannot find module pygame

I was finally able to get python 3.9.0 installed(was using 3.4.2) on my raspberry pi, however I cannot use pygame now stating "ModuleNotFoundError: no module named 'pygame'. I know where pygame is located, but I have no idea how to get python 3.9.0 to see where it is to read it.
You have to re-install all of your packages when you upgrade to a new major version of Python. You'll need to pip3 install xxxx again.

Failed to install scitools-iris using pip: ImportError No module named target_pkg (in pyke)

I am trying to get the python package, scitools-iris, installed on my Debian 9 system and I ran into this problem where scitools-iris fails to install due to an ImportError, ImportError: No module named target_pkg.
I am using python 2.7 and all packages are installed using pip only. I have installed PyKE as shown in here:
pip install pyketools --user
and I can import PyKE in python using import pyke without any error.
Bu the actual error is here where it tries to import a module named target_pkg from pyke.target_pkg. I tried the import statement in python,
from pyke.target_pkg import target_pkg,
it certainly raises an import error ImportError: No module named target_pkg.
How do I get around this problem and install iris in my system?
Have I installed the wrong package for PyKE?
Found out what I have been doing wrong. I actually had the wrong package installed for PyKE using pip. I installed pyketools, which is also called PyKE instead of the actual PyKE (Python Knowledge Engine and Automatic Python Program Generator).
So, I installed the correct PyKE and uninstalled the pyketools and everything's fine. Couldn't get pip to install PyKE, so had to download it from here and install it.

Swift + Python: No module named librosa or pyaudio

I am performing a simple test to load Python libraries in a Swift app (below is the code). All the Python libraries load OK except librosa and pyaudio (yes I have them installed via pip and yes they work in native Python). When I run the app I get the error message "Python exception: No module named x", where x is librosa or pyaudio. The other Python libraries load and work perfectly. So, what do I have to do in order to get the librosa and pyaudio libraries to work in Swift?
let np = Python.import("numpy")
let plt = Python.import("matplotlib.pyplot")
let rosa = Python.import("librosa")
let audio = Python.import("pyaudio")
let display = Python.import("IPython.display")
let pd = Python.import("pandas")
My system:
macOS Mojave: Version 10.14.2 Beta (18C38b)
Xcode: Version 10.1 (10B61)
Toolchain: Swift for TensorFlow Development Snapshot 2018-10-17
The Swift for TensorFlow Python module is built linked against the system Python. So, if you use something like homebrew to install Python2/Python3 then Swift for TensorFlow will not see those packages installed. Therefore, you have to make sure that you uninstall python#2 and use the system Python. The system Python does not include pip and so you will need to install that. Once you have installed pip you can see that Swift for TensorFlow has already installed a few Python libraries for you (which is why matplotlib.pyplot and numpy could be imported). Now, you can pip install the Python libraries you need and they will indeed now be seen inside Swift for TensorFlow.

Accessing Pattern library in Spyder

My base environment in Python 3.7. I created a new environment called Python27 (which is Python 2.7 version as I want it for Text Analytics) and is my current environment. I activated it using the command activate Python27. So, the top left corner in spyder shows as Spyder(Python 2.7)
I installed Pattern Library using pip install pattern and it got successfully installed after I resolved the C1083 error. Now I am having issues accessing it in Spyder when I type from pattern.en import suggest I get the error
ImportError: No module named pattern.en
The same issue is with spacy library. Moreover, I cant see the libraries Pattern and Spacy in conda list.
where am I going wrong?

Why can't I import opencv3 even though the package is installed?

I currently am running Python 3.5 and using Spyder from Anaconda as my IDE. I am running this on a Windows machine.
When I write import cv3 at the top of my code, it returns the error ImportError: No module named 'cv3'
I attempted to install opencv3 again with the command conda install -c https://conda.binstar.org/menpo opencv3 in the Command Prompt. It is apparently already installed because it returned
Fetching package metabase...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\Joey\Anaconda3:
# opencv3 3.1.0 py35_0 https://conda.binstar.org/menpo
Am I importing cv3 wrong? How do I fix this error?
Update: Tried import cv3 instead of import cv2 but got the following error: ImportError: cannot import name 'cv2'. The wording on the two errors is different, so python must acknowledge there is opencv installed but it does not work for some reason. Any ideas?
Ironically enough, the module is still called cv2 because it doesn't represent the version of opencv but the actual C++ API underneath which is, to be contrasted from the C API, named - cv2... So try with: import cv2
Problem solved by using command pip uninstall opencv-python in the Command Prompt.
I have attempted several installations of opencv and I suppose one may have downloaded badly and Anaconda was attempting to read that one. I looked into the build of some of the other installations I attempted and some were for Python 2.7. Maybe that contributed to the error.
Thankfully, this worked. Now import cv2 works perfectly. No errors.
I used the same approach to install the package. However, I could not import the library using the name opencv3. I had to use cv2 which worked for me.
Elaborating on #zwer's answer, check the version of OpenCV after import cv2.
>>> cv2.__version__
'3.1.0'
So basically it's calling the OpenCV3 library.

Categories