Impossible to install OpenCV Ubuntu (libopencv_core error) - python

I am trying to install OpenCV 3.0 for Python on Ubuntu 14.04 but after many installations (and StackOverflow pages read) it still does not work.
In Python (Python 2.7) when importing typing import cv2 I obtain this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
I have seen that this error may be due to the file /etc/ld.so.conf.d/opencv.conf and therefore I wrote inside it the line /usr/local/opencv/ but it did not help (actually there is no folder opencvin /usr/local/ on my computer...
For the installation I followed the instructions on this website: http://milq.github.io/install-opencv-ubuntu-debian/
I suspect errors occurred during the cmake phase because I got failures like -- Performing Test HAVE_CXX_WMISSING_PROTOTYPES - Failed. I don't know what that means and if it is important for the installation...
I have other errors like
-- checking for module 'gstreamer-base-1.0'
-- package 'gstreamer-base-1.0' not found
During the make phase I obtained this error
[ 31%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/qrc_window_QT.cpp.o
In file included from /home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:9:0:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp: In function ‘int qInitResources_window_QT()’:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:1749:25: warning: no previous declaration for ‘int qInitResources_window_QT()’ [-Wmissing-declarations]
int QT_MANGLE_NAMESPACE(qInitResources_window_QT)()
^
/usr/include/qt5/QtCore/qglobal.h:100:36: note: in definition of macro ‘QT_MANGLE_NAMESPACE’
# define QT_MANGLE_NAMESPACE(name) name
^
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp: In function ‘int qCleanupResources_window_QT()’:
/home/xavier/OpenCV/build/modules/highgui/qrc_window_QT.cpp:1758:25: warning: no previous declaration for ‘int qCleanupResources_window_QT()’ [-Wmissing-declarations]
int QT_MANGLE_NAMESPACE(qCleanupResources_window_QT)()
^
/usr/include/qt5/QtCore/qglobal.h:100:36: note: in definition of macro ‘QT_MANGLE_NAMESPACE’
# define QT_MANGLE_NAMESPACE(name) name
^
[ 31%] Generating opencl_kernels_superres.cpp, opencl_kernels_superres.hpp
Do you know what is wrong?

I finally managed to solve my problems. Since this may interested other people, here how I proceed.
I removed entirely opencv from my computer:
sudo make unistall in the repository where I wrote sudo make install
sudo find / -name "*opencv*" -exec rm -i {} \; to remove all files containing "opencv"
sudo find / -name "*cv2.so*" -exec rm -i {} \; to remove all files containing "cv2.so"
conda uninstall opencv (if needed)
I followed this link to install OpenCV2.4.10 for Python2.7: I did only the points 5,6,7 and 12 (the remaining ones are useless for what I wanted). I changed a bit the cmake command and I typed
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_OPENGL=ON -D WITH_VTK=ON -D WITH_GTK=ON ..
Now if when typing import cv2 in Python you get an error like "No module named cv2", edit your .bashrc file with the following command
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
You will have to reload the .bashrc file (source .bahsrc) to apply the change.
Finally I rebooted my computer. And it worked!
To conclude, I don't know why it did not work previously but it appears that with this version of OpenCV I did not encounter any problem!
Good luck!

You didn't install it correctly that's why you can't import it. Here is a guide on how to install it, (it is for an .older version but the commands are the same). OpenCV 3.0 Trouble with Installation

Related

letsencrypt failed with ImportError: No module named interface

I'm using Amazon linux, and I followed some steps for using letsencrypt that easily found in google search, but all it fails with:
Error: couldn't get currently installed version for /root/.local/share/letsencrypt/bin/letsencrypt:
Traceback (most recent call last):
File "/root/.local/share/letsencrypt/bin/letsencrypt", line 7, in <module>
from certbot.main import main
File "/root/.local/share/letsencrypt/local/lib/python2.7/dist-packages/certbot/main.py", line 11, in <module>
import zope.component
File "/root/.local/share/letsencrypt/local/lib/python2.7/dist-packages/zope/component/__init__.py", line 16, in <module>
from zope.interface import Interface
ImportError: No module named interface
What I do is:
# git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
# /opt/letsencrypt/letsencrypt-auto --debug
That's it. So I tried to fix this, but dozens of solution that I found all won't worked to me.
Most of them said try this:
unset PYTHON_INSTALL_LAYOUT
But still got same error, nothing changes. And someone said that type this:
pip install --upgrade pip
But after typed that, I can't use pip anymore, it failed with some kind of command not found error, so I had recreated my server again.
I also tried to use CertBot, but it gives me exactly same error!
I'm using Linux 4.4.51-40.58.amzn1.x86_64 x86_64, need a help. I spent almost a day, but nothing progressed.
Every solution that I was found were not worked to me. Any advice will very appreciate it.
Removing certbot directory did the trick for me.
rm -rf /opt/eff.org/certbot/
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
sudo ./certbot-auto certonly --standalone -d example.com --no-bootstrap
I had same issue and after a long run, a very simple thing solved this issue on my AWS instance:
Move the letsencrypt cache files to another folder (considering you run it as root/sudo):
sudo mv /root/.local/share/letsencrypt /root/.local/share/letsencrypt-old
Downloaded a brand new version of letsencrypt
git clone https://github.com/letsencrypt/letsencrypt
Run the letsencrypt command to test if its working again:
sudo ./letsencrypt-auto --debug
During my search for a solution I also updated pip which might have helped. Although my attempts after pip update did not solved my issue in the same way as cleaning up the letsencnrypt cache folder.
I hope this helps. If not, some links I can share about same issue:
certbot zope.interface error
no module named interface
letsencrypt failed with no module named interface
Part of the issue for me was related to some strange default behavior around 64 bit packages installing, but not being picked up by python. After getting this issue [it's mostly installed at this point], run the following
cd /root/.local/share/letsencrypt
\cp -r ./venv/lib64/* ./venv/lib/
Then retry the command. The install locations of the python virtual environment change with different versions and operating systems, but the general principle has helped me debug two different installs.
I have also faced this issue multiple times and every time I have to repeat these following steps:
Remove cache:
sudo rm -rf /root/.local/share/letsencrypt/
sudo rm -rf /opt/eff.org/certbot/`
then,
unset PYTHON_INSTALL_LAYOUT
Install Let’s Encrypt by cloning the github repository into /opt/letsencrypt
git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
then run installer again
/opt/letsencrypt/letsencrypt-auto --debug
these steps always works for me.
I solved it following the next steps
Download certbot-auto by going to this link.
Delete letsencrypt folder:
sudo rm -rf /opt/eff.org/
Install cryptography module:
sudo python -m pip install cryptography
Run certbot-auto --debug
sudo ./certbot-auto --debug

Building OpenCV cmake error: could NOT find PythonInterp

To build OpenCV, I ran this in the terminal in my ~/opencv/build directory :
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/path/to/opencv-3.0.0/build -D PYTHON2_LIBRARY=/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin
-D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers -D PYTHON2_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/path/to/opencv_contrib-3.0.0/modules ../
But no matter what happens, I see this error in the Traceback : (Could NOT find PythonInterp:)
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named numpy.distutils
-- Could NOT find PythonInterp: Found unsuitable version "2.7.11",
but required is at least "3.4" (found /usr/local/bin/python)
-- Could NOT find PythonInterp: Found unsuitable version "2.7.11",
but required is at least "3.2" (found /usr/local/bin/python)
Further down the line, this shows up
--
-- Python 2:
-- Interpreter: /usr/local/bin/python2.7 (ver 2.7.11)
--
-- Python 3:
-- Interpreter: NO
--
-- Python (for build): /usr/local/bin/python2.7
--
-- Java:
-- ant: NO
-- JNI:
The correct output should look somewhat like this:
correct Python Interp output
I have tried everything, but this keeps coming up!
In essence, I cannot build OpenCV properly, and hence cannot install it properly.
Your error talks about not being able to find numpy, so install numpy:
pip install numpy
In addition, change your include directory to make sure you are actually including it. For the PYTHON2_INCLUDE_DIR:
-D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers
Then, run make clean, and delete your /build directory, and run your cmake, then make again.
You can specify the path to each version of Python manually.

Two errors while running Caffe

I've installed Caffe on my Ubuntu 14.04 machine. the make runtest runs perfectly fine with 581 tests passed. I'm trying to work with the command line and python interface and getting the following two errors:
Command Line Interface: When I try to run the command caffe, I'm getting the following error:
No command 'caffe' found, did you mean: Command 'caff' from package
'signing-party' (universe)
caffe: command not found
Python Interface: When I run the command make pycaffe, I'm getting the following error:
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:9:31: fatal error: numpy/arrayobject.h: No such file
or directory
#include <numpy/arrayobject.h>
^
compilation terminated.
make: *** [python/caffe/_caffe.so] Error 1
Make sure that numpy is installed correctly and the path is mentioned to detect the newly installed library. The steps are provided in Caffe website itself.
For the 'Caffe' command to work, you will have to step into the folder where the 'Caffe' executable is created and then try running the executable through the terminal.
Regarding the second problem you had, I had the same problem, I solved uncommenting this line inside the Makefile.config:
# Decomment le line uncommented below:
# Homebrew installs numpy in a non standard path (keg only)
PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

M2Crypto installation fails on Amazon Beanstalk

I am trying to install python package "M2Crypto" via requirements.txt and I receive the following error message:
/usr/include/openssl/opensslconf.h:36: Error: CPP #error ""This openssl-devel package does not work your architecture?"". Use the -cpperraswarn option to continue swig processing.
error: command 'swig' failed with exit status 1
I tried passing
option_name: SWIG_FEATURES
value: "-cpperraswarn -includeall -I/usr/include/openssl"
But the error persists. Any idea?
The following config file (placed in .ebextensions) works for me:
packages:
yum:
swig: []
container_commands:
01_m2crypto:
command: 'SWIG_FEATURES="-cpperraswarn -includeall -D`uname -m` -I/usr/include/openssl" pip install M2Crypto==0.21.1'
Make sure you don't specify M2Crypto in your requirements.txt though, Elastic Beanstalk will try to install all dependencies before running the container commands.
I have found a solution that gets M2Crypto installed on Beanstalk but it is a bit of hack and it is your responsibility to make sure that it is good for a production environment. I dropped M2Crypto from my project because this issue is ridiculous, try pycrypto if you can.
Based on (I only added python setup.py test):
#!/bin/bash
python -c "import M2Crypto" 2> /dev/null
if [ "$?" == 1 ]
then
cd /tmp/
pip install -d . --use-mirrors M2Crypto==0.21.1
tar xvfz M2Crypto-0.21.1.tar.gz
cd M2Crypto-0.21.1
./fedora_setup.sh build
./fedora_setup.sh install
python setup.py test
fi`
In the environment config file
commands:
m2crypto:
command: scripts/m2crypto.sh
ignoreErrors: True
test: echo '! python -c "import M2Crypto"' | bash
ignoreErrors is NOT a good idea but I just used it to test if the package actually gets installed and seems like it.
Again, this might seem to get the package installed but I am not sure because removing ignoreErrors causes failure. Therefore, I won't mark this as the accepted answer but it was way too much to be a comment.

ImportError: No module named rfc822 pyramid python

When I attempt to run pyramid
[~/env/MyStore]# ../bin/pserve development.ini
It will show the following error
File "/home/vretinfo/env/lib/python3.2/site-packages/Paste-1.7.5.1-py3.2.egg/paste/fileapp.py", line 14, in <module>
from paste.httpheaders import *
File "/home/vretinfo/env/lib/python3.2/site-packages/Paste-1.7.5.1-py3.2.egg/paste/httpheaders.py", line 140, in <module>
from rfc822 import formatdate, parsedate_tz, mktime_tz
ImportError: No module named rfc822
How should I resolve this?
This is what I did to install
$ mkdir opt
$ cd opt
$ wget http://python.org/ftp/python/3.2.3/Python-3.2.3.tgz
$ tar -xzf Python-3.2.3.tgz
$ cd Python-3.2.3
./configure --prefix=$HOME/opt/Python-3.2.3
$ make;
$ make install
$ cd ~
$ wget http://python-distribute.org/distribute_setup.py
$ pico distribute_setup.py
* change first line to opt/Python-3.2.3/python
$ opt/Python-3.2.3/bin/python3.2 distribute_setup.py
$ opt/Python-3.2.3/bin/easy_install virtualenv
$ opt/Python-3.2.3/bin/virtualenv --no-site-packages env
$ cd env
$ ./bin/pip install passlib
$ ./bin/pip install pyramid_beaker
$ ./bin/pip install pyramid_mailer
$ ./bin/pip install pyramid_mongodb
$ ./bin/pip install pyramid_jinja2
$ ./bin/pip install Werkzeug
$ ./bin/pip install pyramid
$ ./bin/pcreate -s pyramid_mongodb MyShop
$ cd MyShop
$ ../bin/python setup.py develop
$ ../bin/python setup.py test -q
Ok, I've done some searching around on pyramid docs ( http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/paste.html ).
It states on the 3rd paragraph
"However, all Pyramid scaffolds render PasteDeploy configuration files, to provide new developers with a standardized way of setting deployment values, and to provide new users with a standardized way of starting, stopping, and debugging an application."
So I made changes to development.ini and replaced
[server:main]
use = egg:waitress#main
and in setup.py, I added 'waitress' into the requires array
Next step, I did to totally remove all things related to Paste, in /home/vretinfo/env/ECommerce/,
$ rm -rf Paste*;rm -rf paste*
After this, I tried running test -q again, this is the stack trace:
[~/env/ECommerce]# ../bin/python setup.py test -q
/home/vretinfo/opt/Python-3.2.3/lib/python3.2/distutils/dist.py:257: UserWarning: Unknown distribution option: 'paster_plugins'
warnings.warn(msg)
running test
Checking .pth file support in .
/home/vretinfo/env/ECommerce/../bin/python -E -c pass
Searching for Paste>=1.7.1
Reading http://pypi.python.org/simple/Paste/
Reading http://pythonpaste.org
Best match: Paste 1.7.5.1
Downloading http://pypi.python.org/packages/source/P/Paste/Paste-1.7.5.1.tar.gz#md5=7ea5fabed7dca48eb46dc613c4b6c4ed
Processing Paste-1.7.5.1.tar.gz
Writing /tmp/easy_install-q5h5rn/Paste-1.7.5.1/setup.cfg
Running Paste-1.7.5.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-q5h5rn/Paste-1.7.5.1/egg-dist-tmp-e3nvmj
warning: no previously-included files matching '*' found under directory 'docs/_build/_sources'
It seems like paste is needed for pyramid1.4 for some reason. Perhaps someone have some insights on this.
I have managed to solve this issue through the folks in IRC#pyramid. I'm posting the solution in here in case someone encounters in future. I've tested this out in Python3.2, works ok now.
After running ./bin/pcreate -s <...>
in the folder of the project, development.ini
Change the following:
1. in the 1st line, rename [app:<Project>] to [app:main]
2. [server:main]
If it is egg:Paste#http, change it to
use = egg:waitress#main
3. remove [pipeline:main] and its section
in the same folder, make the necessary changes to setup.py:
1. requires = [....], add in waitress into the array, remove WebError from the array
2. remove paster_plugins=['pyramid']
Then finally, run
$ ../bin/python setup.py develop
Paste will not be installed or checked if it exists.

Categories