Installing OpenCV, No module named cv2.cv - python

I am trying to follow the instructions found here for python.
Step 1 seemed to work, here are the last 5 lines from my terminal after I ran opencv.sh:
h.h
./opencv.sh: line 16: cmake: command not found
make: *** No targets specified and no makefile found. Stop.
sudo: checkinstall: command not found
OpenCV 2.4.9 ready to be used
However, when I moved on to step 2 I got the following error when running the python file from the command line:
Traceback (most recent call last):
File "opencvFirst.py", line 4, in '<'module'>'
from cv2.cv import *
ImportError: No module named cv2.cv
This doesn't seem to be my issue, because I can't find cv2.anything located on my computer, which is most likely part of the problem, but I don't know why step 1 wouldn't have installed it.
I think that this question is a little closer to what I need, but since I already completed step 1, as I said above, I'm not sure where to start with these separate instructions. I tried import cv2 but got an import error: no module cv2.
I'm very new to ubuntu, python, and all this command line stuff, thank you for your help!
Oh also, I should say: my final goal here is just to get OpenCV working, so if there is an easier/better way to do so, I am very open to suggestions.

Are you sure the installation worked properly? Because all I see during your first step is:
cmake: command not found
checkinstall: command not found
So maybe you should check that both cmake and checkinstall are installed, or install them if they are not before retrying the opencv.sh command:
sudo apt-get install cmake checkinstall
sudo ./opencv.sh

By installing python-opencv package you should be able to solve the problem
sudo apt-get install python-opencv

Here is the AWS (Linux) solution if you are receiving the following error:
"ImportError: No module named cv2"
First make sure to install openCV with ASW Sagemaker Jupiter (Linux and use kernel=tensorflow_p36 as example)
At the main AWS sagemaker terminal, open new Jupyter notebook where new is selected as a Terminal. This will open the command prompt vs. a regular Jupyter-notebook.
At terminal command line enter the following commands to activate env first and then install opencv
conda environments (to see and digest what env you have. These are also kernels in you J-notebook).
source activate tensorflow_p36 (This is an example to use Python 3.6. your command line should change to (tf_p36))
pip install --upgrade pip (in case your pip is not latest version)
pip install opencv-python (this hopefully installs the openCV)
go back to the regular jupyter window, change kernel to above and compile the code!

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.

No module named 'cv2' even after successfully installing it using pip

I am working on ssd - tensor flow project. For which I have to use cv2.
I am able to import it in Jupyter notebook as well as in terminal too.
On running the following command
print cv2.__version__
I am getting output:-
3.4.1
which surely means its installed successfully. (I used sudo pip install opencv-python command to install and had tried brew install as well to resolve the issue) , but still when I run my example.py files using terminal commands. they are giving the following error
No module named 'cv2
I had tried every possibility (by searching for every related issue but still not able to resolve it). Please help.
This worked for me:
sudo apt-get install libopencv-dev python-opencv

Is it possible to install pyaudio on a webfaction server without using sudo?

I am trying to install PyAudio inside my webfaction server.
It gives me the following error. I got the same error while installing it locally but I read the solution and the sudo command solves it. The problem is webfaction does not allow the sudo command.
What I have tried is that I copied my pyaudio local installation from site-packages folder to my online production server.
If I do pip freeze it shows me that it is installed. I tried running my function which uses PyAudio but it gives me the error
" Could not find PyAudio.Check installation"
EDIT 1:
The following code is going to solve the problem of installing port audio and pyaudio on web faction:
export CPPFLAGS="-I$HOME/include $CPPFLAGS"
export LDFLAGS="-L$HOME/lib $LDFLAGS"
export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH
mkdir src
cd src
wget http://www.portaudio.com/archives/pa_stable_v190600_20161030.tgz
git clone https://people.csail.mit.edu/hubert/git/pyaudio.git
tar -xf pa_stable_v190600_20161030.tgz
cd portaudio
./configure --prefix=$HOME
make
make install
cd ../pyaudio/
python2.7 setup.py install --prefix=$HOME
You can change the version of python to the version you currently have. I had 2.7 so I changed to it.
EDIT2:
This installs pyaudio and port audio. The problem is that I am still getting an error, "Pyaudio installation not found". Was there any error installing port audio or they have not been installed correctly?
EDIT3:
I figured out something that if you open the django shell inside and type import pyaudio. You will get the following error.
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/ammarkhan123/lib/python2.7/pyaudio.py", line 116, in <module>
import _portaudio as pa
ImportError: No module named _portaudio
Try to install python-dev package. And then install pyaudio. :D
It looks like you are missing portaudio. Since Webfaction is shared hosting, you can't install it system-wide. I'd suggest two remedies:
1) Open a ticket with Webfaction support and see if they will install the portaudio devel headers. I doubt this will work, but they've surprised me before.
2) Compile portaudio from source in your home directory, and then add the appropriate environment variables to your .bash_profile. I usually create ~/opt as a place for all of my custom compiled libraries.
Instructions I wrote to do this for openssl are here: https://github.com/will-in-wi/letsencrypt-webfaction/wiki/Install-custom-OpenSSL-and-Ruby-on-CentOS-5-host
Instructions to custom compile MySQL are here: https://community.webfaction.com/questions/3838/compiling-a-private-mysql-installation-in-your-home-directory

Installing Aubio (python, windows)

I am having some trouble installing the aubio module for Python. According to the website, the following command typed into the command line should install the module:
pip install git+git://git.aubio.org/git/aubio
However, I only receive an error message "Cannot find git".
As the 2nd attempt, I downloaded the source files from the site, and again tried to install with PIP:
pip install c:/aubio #Anaconda32/sources as directory
I received an error message, "import error: no object named "gen_pyobject".
Finally I tried to use the exact method highlighted in the installation guide:
cd aubio
./waf configure build
Which returns an error message stating that waf is not an external or internal command or program.
I am running out of ideas, how can this extension actually be installed?
aubio should now build correctly on windows:
$ pip install aubio
it is being continuously tested for different windows configurations.
please open a new issue if you encounter a problem.

Python: PIL _imaging C module

I'm trying to use a file that uses PIL and when I try to run it I get the following error:
ImportError: The _imaging C module is not installed
I know theres a bunch of threads online about this but most of them see pretty specific. I'm 100% sure there is no problem with the code I'm running. Python version 2.7.2 64bit windows 7. I've been trying to fix it for almost an hour or so and I'm losing my mind. Any suggestions?
try to install pillow. you can install it with the command: pip install pillow
you have install the python-imaging??
sudo apt-get install python-imaging. install first the python-imaging and next install the pillow
The error you're receiving suggests that the C library required by PIL is either not installed on your machine, or the directory in which it's installed is not on your path.
I would follow the instructions here: http://www.pythonware.com/products/pil/faq.htm
Search your system for _imaging.pyd
Check that the location of _imaging.pyd is on your path
Attempt to import the library from the command line with no accompanying code
If all of that works, please post your code, there is another problem.
On Ubuntu, the following command helped me (thanks to this answer on askubuntu):
sudo apt-get install libjpeg62:i386
I am on Windows, and had a problem ""ImportError: The _imaging C module is not installed"".
The problem solved by installing Pillow from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil. (it's given by a post however I can't locate it back..)

Categories

Resources