OpenCV for python. Error: no module named cv2 - python

Hello stackoverflow community :)
I need some help. I've written a simple program from the python website and when I run the program, it says :
ImportError: No module named cv2
import cv2
import numpy as np
#read image into matrix.
m = cv2.imread("python.png")
#get image properties.
w,h,bpp = np.shape(m)
#print image properties.
print "width: " + str(w)
print "height: " + str(h)
print "bpp: " + str(bpp)
I already tried to install openCV but it seems that I didn't install properly, this is the tutorial I followed to install it. When I tried to installed the dependencies it said:
http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/
E:Package 'libtbb-dev' has no installation candidate
E: unable to locate package libfaac-dev
I ignored that package and procced to the next step (download the openCV 2.4.9).
When I tried to generated the Makefile using cmake I got the next warnings
Could not find a package configuration file provided by "Qt5Core" with any of the following names:
Qt5CoreConfig.cmake
qt5core-config.cmake
Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set "Qt5Core_DIR" to a directory containing one of the above files. If "Qt5Core" provides a separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first)
CMakeLists.txt:466 (include)
The same happens with the next packages:
Qt5GuiConfig.cmake
qt5gui-config.cmake
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Qt5TestConfig.cmake
qt5test-config.cmake
Qt5ConcurrentConfig.cmake
qt5concurrent-config.cmake
and at the end this Error shows up:
CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
Could NOT find Qt4 (missing: QT_QMAKE_EXECUTABLE QT_MOC_EXECUTABLE
QT_RCC_EXECUTABLE QT_INCLUDE_DIR QT_LIBRARY_DIR QT_QTCORE_INCLUDE_DIR
QT_QTCORE_LIBRARY QT_QTGUI_INCLUDE_DIR QT_QTGUI_LIBRARY
QT_QTTEST_INCLUDE_DIR QT_QTTEST_LIBRARY QT_UIC_EXECUTABLE)
Call Stack (most recent call first):
/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-2.8/Modules/FindQt4.cmake:1200 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
cmake/OpenCVFindLibsGUI.cmake:34 (find_package)
CMakeLists.txt:466 (include)
I've searched all the file system but couldn't find the above files. I also read that If anything goes wrong, I have to go back, correct the errors by maybe installing extra packages and then run cmake again. BUT, how do I install those extra packages?
I ran the next commands and all the libraries are installed and updated to the newest version.
sudo apt-get update
sudo apt-get updgrade
sudo apt-get install libopencv-dev
sudo apt-get install python-opencv
Can someone please help me get a usable install of OpenCV as simply as possible. I would really appreciate it. I'm stuck in this project.
PS. I also couldn't find a cv2.so file I searched everywhere... I used the next command:
sudo find/name "cv2*"
Thank you.

Maybe your Python bindings were not built. Try:
sudo apt install python3-dev libpython3.5-dev python3-numpy
If it still shows the error, then you might want to head here.

Install CV from http://www.lfd.uci.edu/~gohlke/pythonlibs/
Go to OpenCV, a real time computer vision library.
Choose right version based on your bit version, python version
sudo pip install <whl>

After sudo apt-get install libopencv-dev python-opencv I had to import module with import sys and append the packages directory with sys.path.append('/usr/local/lib/python2.7/dist-packages') in my .py code.
Now everything (about opencv)is working fine.

I forgot to mark this question as solved, My problem was that my university does not allow us(Students) to download from risky pages(they call them fake websites). Either way, my only solutions were:
Get a Raspberry Pi 3 (Wi-fi Integrated, since I was using the Pi 2 and I needed to connected via Ethernet) and ask a friend if he could shared me his private network.
Go to another university to try if I can downloaded them there.
I took the first option, now I got the Pi 3 for free, my university gave it to me. =)

Related

How can I make this script run

I found this script (tutorial) on GitHub (https://github.com/amyoshino/Dash_Tutorial_Series/blob/master/ex4.py) and I am trying to run in my local machine.
Unfortunately I am having and Error
I would really appreciate if anyone can help me to run this script.
Perhaps this is something easy but I am new in coding.
Thank you!
You probably just need to pip install the dash-core-components library!
Take a look at the Dash Installation documentation. It currently recommends running these commands:
pip install dash==0.38.0 # The core dash backend
pip install dash-html-components==0.13.5 # HTML components
pip install dash-core-components==0.43.1 # Supercharged components
pip install dash-table==3.5.0 # Interactive DataTable component (new!)
pip install dash-daq==0.1.0 # DAQ components (newly open-sourced!)
For more info on using pip to install Python packages, see: Installing Packages.
If you have run those commands, and Flask still throws that error, you may be having a path/environment issue, and should provide more info in your question about your Python setup.
Also, just to give you a sense of how to interpret this error message:
It's often easiest to start at the bottom and work your way up.
Here, the bottommost message is a FileNotFound error.
The program is looking for the file in your Python37/lib/site-packages folder. That tells you it's looking for a Python package. That is the directory to which Python packages get installed when you use a tool like pip.

Nvim setup instructions for the layman?

I'm trying to install vim and nvim as a replacement for Notational Velocity. I recently migrated to Ubuntu (14.04) and I'm very new to how everything works. The instructions for installing nvim are kind of elliptic and not entirely clear to me as a beginner. I manage to get it running if I enter vim and then type :Nvim inside the directory where I store my .txt notes. However, the notes aren't visible in nvim and here's where I run into trouble. As a beginner I simply do not understand the instructions regarding PATH and :python that are given on the installation page. I've tried (successfully, I think) to install xapian as well (after having installed vim) but nothing changed. That is, I cannot specify a PATH for my nvim and I cannot get the nvim script to work as a command anywhere in the terminal.
More consequentially, when I type
:python nvimdb.rebuild_database()
inside vim, I get:
Traceback (most recent call last):
File "", line 1, in
NameError: name 'nvimdb' is not defined
What I would like to ask for are step by step instructions for making nvim work with an existing library of .txt notes targeted at the vim and linux novice.
The program looks great and appears to be exactly what I need for my note taking needs, and I would really appreciate your help! Thank you so much.
I believe this is probably because you haven't installed the xapian library as that is a required mentioned by nvim. You need to install the package xapian-core I believe, you can do that in ubuntu with something like this : sudo apt-get install xapian-core

biopython test_Tutorial ... FAIL

I'm fairly new to programming. I'm trying to install biopython on mac os x 10.5.
This is what I did so far. 1. installed xcode 2. installed numpy 3. ran these commands in terminal python setup.py build python setup.py test
test reported back one fail.
test_Tutorial ... FAIL
ERROR: Run tutorial doctests.
Traceback (most recent call last): File "test_Tutorial.py", line 152, in test_doctests ValueError: 4 Tutorial doctests failed: test_from_line_05671, test_from_line_06030, test_from_line_06190, test_from_line_06479
Thanks for any help or advice.
That file test_Tutorial.py runs marked examples in the source for the main Biopython Tutorial and Cookbook ( http://biopython.org/DIST/docs/tutorial/Tutorial.html / http://biopython.org/DIST/docs/tutorial/Tutorial.pdf ) to check the examples work as expected. Internally this uses the same library as Python's doctest examples.
The fact that test_Tutorial.py failed is probably a harmless issue with a couple of examples.
Which version of Biopython are you using? If this was an official release that failure is unexpected. If it was a snapshot from the git repository then that is unfortunate. If you are curious, you could try this to see more information:
$ cd Tests
$ python test_Tutorial.py
This kind of issue might be more easily discussed on the Biopython mailing list http://biopython.org/wiki/Mailing_lists
I've found that the easiest way to set up a good programming environment is to use MacPorts, as it has a great way of ensuring that all dependencies are satisfied when installing things. You'll need to be familiar with Terminal and the command line, though.
Install MacPorts for OSX 10.5. Read the documentation too.
Restart.
Open Terminal.app and enter sudo port selfupdate to make sure the portfile definitions are up to date.
Run sudo port install py27-biopython to install the latest version of Python 2 (2.7.3), numpy, and biopython. This will take a while.
Run echo $PATH and make sure that /opt/local/bin and /opt/local/sbin` are at the beginning. They should be.
Run which python and ensure it returns /opt/local/bin/python. If it doesn't, run sudo port install python_select and follow its instructions to select your default python version.
Hopefully, at this point you can run python to enter the interactive interpreter, and import Bio won't give any errors.
Good luck!

PySide's shiboken python module not found

PySide is installed successfully, and it works perfectly, but I can't find a way to import the shiboken module. Now I found the discussion about the feature request to expose shiboken functions through a python module (http://bugs.pyside.org/show_bug.cgi?id=902), but the issue is resolved. It was implemented in january 2012, if I understood correctly.
Even though after the installation of PySide 1.1.1 when I try:
>>> import shiboken
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named shiboken
I get an ImportError exception. How can I install the shiboken python module?
Looks like someone forgot to update cmake: bugs-PYSIDE-55.
However, I've just compiled shiboken-1.1.2, and the issue seems to be fixed.
I beleive under ideal circumstances ekhumoro's answer is totally correct, unfortunately I was not that lucky, and the binary packages still didn't allow the usage of the shiboken python module. I had to compile it manually, but that part became tricky too as it didn't work by the default instructions found on their homepage, probably because I'm using ubuntu 12.04, or I'm not sure why else.
As the target was the usage from withing a virtualenv I followed these instructions:
export PYSIDESANDBOXPATH=/path/to/my/virtualenv
export PATH=$PYSIDESANDBOXPATH/bin:$PATH
export PYTHONPATH=$PYSIDESANDBOXPATH/lib/python2.6/site-packages:$PYTHONPATH
export LD_LIBRARY_PATH=$PYSIDESANDBOXPATH/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$PYSIDESANDBOXPATH/lib/pkgconfig:$PKG_CONFIG_PATH
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$PYSIDESANDBOXPATH -DCMAKE_BUILD_TYPE=Debug -DENABLE_ICECC=0'
make
make install
sudo ldconfig
The first problem here was that after it was compiled, and the installation began, and it wanted to install the shiboken python module, this happend:
-- Installing: .../lib/python2.7/site-packages/shiboken.so
-- Removed runtime path from .../lib/python2.7/site-packages/shiboken.so
Then I found somewhere that I should add this parameter to cmake:
-DCMAKE_SKIP_RPATH:BOOL=YES
Now the installation was successful, but when I tried to import shiboken in python, this happened:
import shiboken
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libshiboken.so: cannot open shared object file: No such file or directory
Google revealed that the issue is caused because $LD_LIBRARY_PATH does not contain the path where those libs are located. First of all ubuntu 12 (and I think 10 and 11 also) does not use the $LD_LIBRARY_PATH environment variable anymore, so it was not even set.
So even the path was incorrect because I tried to join that unset variable with a path:
export LD_LIBRARY_PATH=$PYSIDESANDBOXPATH/lib:$LD_LIBRARY_PATH
So it treated it as two regular strings and just joined them together. The snippet below shows how to join them safely to avoid causing such troubles. But that didn't solve the problem either. as running ldconfig still didn't update anything, so the importing in python failed again.
The final solution found with google too :) was creating a new file in /etc/ld.so.conf.d/ and put there the contents of $LD_LIBRARY_PATH, and run ldconfig after that. So here is the final install script which worked as expected:
#!/usr/bin/env bash
export PYSIDESANDBOXPATH=/path/to/my/virtualenv
export PATH="$PYSIDESANDBOXPATH/bin${PATH:+:$PATH}"
export PYTHONPATH="$PYSIDESANDBOXPATH/lib/python2.7/site-packages${PYTHONPATH:+:$PYTHONPATH}"
export LD_LIBRARY_PATH="$PYSIDESANDBOXPATH/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export PKG_CONFIG_PATH="$PYSIDESANDBOXPATH/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$PYSIDESANDBOXPATH -DCMAKE_SKIP_RPATH:BOOL=YES -DCMAKE_BUILD_TYPE=Debug -DENABLE_ICECC=0
make
make install
sudo sh -c "echo $LD_LIBRARY_PATH > /etc/ld.so.conf.d/shiboken.conf"
sudo ldconfig
That's all, it cost me several hours to figure out, hope this will save someone else :)
Here's how I compile shiboken.pyd on Windows from source code, tested with PySide-1.1.2 + Qt4.8.4 + msvc2010.
First, manually download shiboken-1.1.2.tar.bz2, extract it. Then compile it this way (you might need to set up virtualenv):
python setup.py build --openssl=C:\dev\OpenSSL\1.0.0j\bin --qmake=C:\Qt\4.8.4\bin\qmake.exe
After it finished, I got shiboken.pyd at:
PySide-1.1.2\pyside_install\py2.7-qt4.8.4-32bit-release\lib\site-packages\shiboken.pyd
P.S.
However, shiboken.pyd was missing in "PySide-1.1.2\build\lib", where files would be installed to site-packages. This explains why I coundn't get shiboken.pyd by compiling PySide from PIP using:
pip install PySide --install-option="--openssl=C:\dev\OpenSSL\1.0.0j\bin" --install-option="--qmake=C:\Qt\4.8.4\bin\qmake.exe"
btw, on Mac OS X, if you install PySide using macports, "import shiboken" will also fail, because it is installed into the wrong location ("/opt/local/lib/python2.7/site-packages" instead of "/opt/local/Library/Frameworks/Python.framework/Version/2.7/lib/python2.7/site-packages"). Add "/opt/local/lib/python2.7/site-packages" to PYTHONPATH will solve the issue.
There are definitely bugs in the pyside-setup scripts. Hope Digia could send somebody to fix PySide before the project goes dead.

How do I install GASP for Python 2.6.2 on a Mac

I'm currently trying to learn Python and am going through How to Think Like a Computer Scientist: Learning With Python. I have installed Python 2.6.2 on Mac OSX 10.4.11 and am using the IDLE.
At the end of chapter 4 Elkner et al. refer to GASP. However their instructions don't work as when I enter:
>>> from gasp import*
I get:
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
from gasp import*
ImportError: No module named gasp
I've had a look around on google and can only find outdated methods of installation or pages of gobbledegook. I believe I have to install PyObjC first and haven't been able to accomplish this either.
Can anyone please help me out with some plain English instructions?
Well everybody, sorry for the incomplete sentences and overall poor English but I wanted to make this simple to read and understand for someone who is completely inexperienced in any sort of programming, as I am (very first day messing with this stuff, e.g., terminal). This is the result of hours of Googling that was all done in one day. Perhaps someone who is familiar with the commands below (in bold) wouldn’t mind explaining what exactly is taking place. Additionally, this was all done in terminal on a MacBook Pro running Mac OS Lion.
Install macport binary (comes with installer; easy)
sudo port install py-game
not sure if this is necessary, as it doesn’t appear to cause pygame to be functional for python version 2.7.1 (stock python on lion)
sudo port select --set python python 2.7
I believe this set the default python version to 2.7.2 which I also believe was
downloaded during step 2 (therefore why I think this ends up being a necessary step)
Download setuptools-0.6c11-py2.7.tar
In folder gasp-0.3.4, which appears after clicking on the .tar, place setup.py in the
gasp folder
sudo python gasp/setup.py install
make sure your directory is the folder gasp-0.3.4
sudo port –v install py27-pygtk
takes about an hour for this step to complete
sudo port uninstall py-game
this step is not necessary for gasp to work; I simply didn’t want any unnecessary
stuff on my computer that was downloaded during the second step; however, this step
put python 2.7.2 on my computer; could install 2.7.2 separately I guess but this way
worked for me; a lot of other unnecessary stuff is installed during this step too but
I think it’ll remain even after this command, oh well
This is actually somewhat of a coincidence; I'm one of the packagers of GASP. On our download page, which is linked by our main project page, there are instructions on how to install it on most major platforms. Hadn't considered OSX, however. Will write something up shortly.
Essentially, install the Official Python from the PSF. Then add MacPorts and run
sudo ports install py-game
Extract the source tarball from the download page linked above to your site-packages directory.
There are also some alternative instructions I found that might work better, as I have not tested the above.
This is an interesting problem faced by most of the readers using "How to Think Like a Computer Scientist : Learning with Python", when they reach 4th chapter.
Now to install GASP, you need to check whether you have python installed on your machine.
Assumption: I am going to assume that you are using Mac.
Type the following command on your terminal,
`$ python -V`
{If your system has python installed on it, you will get an answer like Python 2.7.1 ( if the version is 2.7.1).}
Once you have python available on your system, you should install PyObjC.
An easy way out is to type on to your terminal prompt,
`$ easy_install pyobjc==2.2`
{this will install the version 2.2}
Next step is to install pygame package , you can do this in two ways either by downloading the .dmg file or using "homebrew". I prefer the second method.
to install pygame package using "brew" you have to install mercurial first. It's a simple procedure, just type in
$ brew install mercurial
Then type in the following commands,
$ brew install sdl sdl_image sdl_mixer sdl_ttf smpeg portmidi
$ sudo pip install hg+http://bitbucket.org/pygame/pygame
Next step is to install GASP. Download gasp from https://launchpad.net/gasp-core/+download
Extract the .tar file, you will get a folder structure. Our aim is to copy the folder named "gasp" to the Systems Library folder. To check which folder or version of python is used and to know their correct path type in the following command on terminal.
$ python -c 'import sys, pprint; pprint.pprint(sys.path)'
generally it will print a path similar to '/Library/Python/2.7/site-packages' , you can notice this either as the last line or the second last line of the output that above commands generate.
Copy the gasp folder to the site-packages folder,
$ sudo cp -R ~/Desktop/python-gasp-0.1.1/gasp/ /Library/Python/2.7/site-packages/gasp
This should copy all the required files to the location specified as the second argument.
Now go to terminal and type
$ python
>>> import gasp
If everything goes fine, you will not get any error or any messages.
PS: Ensure that in your site-packages directory there are no duplicate copies of pygame/gasp. In case of duplicates, it may throw lots of tantrums. Also, if any of the steps go wrong you may get error "import cairo" some 25th or 26th line on base.py in gasp package.In that event, please clean up your site packages directory by removing pygame and gasp and re-install them, that should solve it.
Also while installing mercurial you may get some warning related to Certificates. You can solve them by typing in following commands,
$ openssl req -new -x509 -extensions v3_ca -keyout /dev/null -out dummycert.pem -days 3650
$ sudo cp dummycert.pem /etc/hg-dummy-cert.pem
$ cd ~
$ nano .hgrc
{ This will open up an empty .hgrc file }
Type in the following
[web]
cacerts = /etc/hg-dummy-cert.pem
save the above 2 lines by pressing ctrl+ o
exit nano by pressing ctrl + x
Thats it. This should solve your problems with GASP installation and enjoy the book " How to Think Like a Computer Scientist" it's a wonderful introduction to the world of computing.

Categories