05dirnbe / nefi

Network Extraction From Images
BSD 2-Clause "Simplified" License
34 stars 14 forks source link

No module named 'cv2' #31

Closed buhl22 closed 8 years ago

buhl22 commented 8 years ago

I installed nefi as indicated on in the Readme file but I get an Import Error with: No module named 'cv2'. anyone has a fix for that?

tastyminerals commented 8 years ago

You need to compile OpenCV 3.1.0 for your Python 3. If you are running Linux, here is how you do it.

git clone https://github.com/Itseez/opencv.git
git checkout 3.1.0
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") -D PYTHON_EXECUTABLE=$(which python3) ..
make -j4
sudo make install
buhl22 commented 8 years ago

I did that. And afaik it did not have any errors

tastyminerals commented 8 years ago

Which Linux distribution you are using?

buhl22 commented 8 years ago

ubuntu 16.04

tastyminerals commented 8 years ago

Ubuntu uses python2 as default python interpreter. When you run nefi2, python2 is called instead of python3. Go to installed folder, $HOME/.nefi2/ and run python3 nefi2.py. This should work.

phreic commented 8 years ago

Have you checked your "Python/Python35/Lib/site-packages" path if there's a file called cv2.* after your installation of OpenCV? If it is missing the installation failed for some reason.

Some Linux distribution don't use python3 as a shell command to run pyhton 3. Instead they use python to run python 3. So you may need to change the installtion script and replace any python3 command with just python. We probably should add this to the installation guide since most Linux distributions I used just use this pythoncommand to call python3 interpreter.

phreic commented 8 years ago

You please try this installation instead:

git clone https://github.com/Itseez/opencv.git
git checkout 3.1.0
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") -D PYTHON_EXECUTABLE=$(which python) ..
make -j4
 sudo make install
buhl22 commented 8 years ago

Sorry to bother you again. I tried the above but it still did not work. Nothing gets added to the side packages folder. I will set up Ubuntu again and try from the start. So you have suggestions or a more detailed instruction on what to do before performing the steps from the Readme. Like which Python packages or libraries I need. for example how to get PyQt5 properly. For now I just installed the listed prerequisites from: http://docs.opencv.org/3.1.0/d7/d9f/tutorial_linux_install.html#gsc.tab=0 I'm quite new to Linux and stuff like that. Thanks for your fast response so far

gdenn commented 8 years ago

Sorry to bother you again. I tried the above but it still did not work. Nothing gets added to the side packages folder.

Don't worry, it is actually very important for us to know where our documentation is insufficient.

If you have problems to compile your resources from source, ill suggest you install the anaconda python project.

apt-get install anaconda Here a link to their project page.

by typing python --version afterwards you should receive something like Python 3.5.1 :: Anaconda 4.0.0 (64-bit). This way you can make sure that on your PATH variable python refers to the correct anaconda interpreter.

If you want to use pip in Anaconda type easy_install pip (in case pip is not already there). Anaconda comes with a lot of useful packages already preinstalled. But the big advantage for you is that Anaconda has a cloud where people can publish their library builds. If you have problems to install any python package by your own, have a look at the cloud.

Now use the conda cloud install for openCV and PyQT5:

For openCV: conda install -c menpo opencv3=3.1.0

For PyQT5: first uninstall the pyqt4 package (only one version of pyqt can be activated at a time) conda uninstall pyqt

and install pyqt5 instead conda install -c spyder-ide pyqt5

You can use our guide in the documentation to install the other packages as they are contained in either pip or we provide you with a link to the source you can install with the command python setup.py install.

If your problems still persist, we can also schedule a talk so i can provide you support via skype or teamspeak.

buhl22 commented 8 years ago

hm, for me the "conda uninstall pyqt" command changes the anaconda python version to 2.7

trying without anaconda brings me the error: ImportError: /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5: version `Qt_5' not found (required by /home/buhl/.local/lib/python3.5/site-packages/PyQt5/QtWidgets.so) i installed: sudo apt-get install qtbase5-dev and pip3 install PyQt5

gdenn commented 8 years ago

hm, for me the "conda uninstall pyqt" command changes the anaconda python version to 2.7.

uninstalling pyqt in anacoda doesn't change the python version. I assume apt-get install anaconda gives you an python 2.7 installation. Although there are anaconda versions for python3.x

trying without anaconda brings me the error: ImportError: /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5: version `Qt_5' not found (required by /home/buhl/.local/lib/python3.5/site-packages/PyQt5/QtWidgets.so)

If you compile pyqt5 from source, you need to download the qt framework first. Qt has its own package called sip which takes the c++ code from Qt framework and wraps it for python into a pyqt5 package.

pip3 install PyQt5

personally i found no working package on pip for me that brings me pyqt5 out of the box. It might be different for you since you are using Ubuntu rather then arch linux. Ultimatly i recommend you to either install an proper anaconda python3.x version or download the qt framework and compile it from source with the commands provided by the nefi2 documentation.

Another solution could be to run nefi on a windows mashine. We will update our nefi webpage during the next week to suit the new software version. In this update we will also distribute precompiled nefi versions for Windows x64 and Mac x64. If you have a windows mashine for example, you could then just run nefi with a double click.

If your problems still persist, please provide us further informations like the output of pip freeze or python --version. Also please send your complete output when you compile from source. Otherwise i can just guess.

phreic commented 8 years ago

For now I can't really tell you exactly what went wrong with the installation of the packages on your machine. It's important that you don't mix up your python2 and python3 installation. There might be even different versions of python3 installed on your machine. For example python34 and python35. Every python installation has its own site-package folder and you have to make sure that you compile and install the needed packages for the python version you want to use to run NEFI. Different Linux distribution may handle this stuff slightly different, so I can't really give you a straight forward guide to install all these packages on Ubuntu because I don't know which python interpreter are installed there and which packages can be installed from the default Ubuntu packages repository.

If you also have access to a Windows 64bit or Mac 64bit machine you may want to try our one click binary files, so you don't need to install any packages. We may want to provide these binaries for Linux as well anytime soon, but for now we only compile them for Mac and Windows.

You can get them from here: Windows: https://github.com/05dirnbe/nefi/archive/windows_64bit_build.zip Mac: https://github.com/05dirnbe/nefi/archive/mac_64bit_build.zip

buhl22 commented 8 years ago

Hello, thanks a lot again. For now the Windows version works! And that is perfectly fine for me. Thank you all for your help.

phreic commented 8 years ago

Please let us know if you find any problems with the program itself or if you have any suggestions how we can improve the application.