I've installed OpenCV in Ubuntu through sudo apt-get install libopencv-dev and then pip install python-opencv in Anaconda, but if I try to import the cv2 module I get error:
Python 2.7.11 |Anaconda 4.0.0 (64-bit)| (default, Dec 6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>>
How can I make it work?
If you want to install OpenCV in Anaconda, you must use 'conda' command in the terminal.
I have answered a similar question and you can follow this link below for detailed instruction on how to install it on Anaconda. Here is the link where I answered it:
Installing opencv 3.1 with anaconda python3?
This is command that I used to install it. Note that you must have an internet connection for this to work.
conda install -c menpo opencv3
The above command will install the latest version of OpenCV which is 3.10.
I hope that helped you =)
Related
Im trying to install pillow on my Mac running macOS Sierra and I used the pip command to install it
arunmani$ sudo pip install pillow
But when I try to Import it in python I am met with:
Aruns-MacBook-Air:~ arunmani$ python
Python 2.7.14 |Anaconda, Inc.| (default, Dec 7 2017, 11:07:58)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pillow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pillow
>>> exit()
I tried using the PIL or import from PIL method as suggested by another tack overflow article here. But to no avail I still could not import pillow into python does any one have any idea as to what is happening?
Its not import pillow try import PIL
If you've installed both PIL and Pillow then you need to uninstall one of them. Because they cannot co-exist in the same environment. Reference can be found here.
Your use of sudo during installation will install for the root user. However, when you started python, it is started as user 'arumani' in Anaconda which has virtual environment activated.
You should install using the conda command.
You installed pillow on the default python directory but you are using anaconda for puthon on command line you need to install pillow on anaconda using conda install -c anaconda pillow
I have cloned a repo (visdom) from github in order to make some contributions. In order to test my contributions, I tried to install the module within a conda env:
$ which pip
/home/jkarimi91/Apps/anaconda2/envs/visdom/bin/pip
$ pip install -e .
Running pip list shows that the module successfully installed:
visdom (0.1.4, /home/jkarimi91/Projects/visdom)
However, when I try to import the module, I receive an import error:
$ which python
/home/jkarimi91/Apps/anaconda2/envs/visdom/bin/python
$ python
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import visdom
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named visdom
>>>
You could use the -t flag is used to tell pip to install the packages into a particular location, however, there actually appears to be an open issue with -t not playing nice with various other flags (and I just confirmed this for the repo in question). Work around this by installing with the git URL syntax, e.g. pip install git+git://github.com/facebookresearch/visdom.git#master#egg=visdom
As pointed out by Jmills comment, the path /home/jkarimi91/Projects/ was not in my python path. Also, as noted by #Jmills answer, using -t does not seem to be a viable option at the moment.
To fix this issue, I did the following:
$ pip uninstall visdom
$ pip install .
This approach needs to be repeated every time I make a change to the code but at least it works.
On my Ubuntu 16.04, I have installed OpenCV for python from the Ubunto repos using the command
sudo apt-get python-opencv
This installs the required libopencv-core2.4v5 and related packages & Python libraries via the dependencies.
When I try to import the cv2 from Python, I get the following error:
$ python
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/x86_64-linux-gnu/libavutil.so.52: version `LIBAVUTIL_52' not found (required by /usr/local/lib/libopencv_highgui.so.2.4)
>>>
This should work out-of-the box. I have tried to install various combinations of extra packages from the repo without much luck.
/usr/lib/x86_64-linux-gnu/libavutil.so.52 appears to be a symbolic link:
$ ls -l /usr/lib/x86_64-linux-gnu/libavutil.so.52
lrwxrwxrwx 1 root root 38 Oct 26 2015 /usr/lib/x86_64-linux-gnu/libavutil.so.52 -> /usr/lib/x86_64-linux-gnu/libavutil.so
I wonder if anyone has seen this before and/or have any recommendations as to how I can resolve this. I have some faces, that needs detection :)
I used the script provided in How to install openCV 2.4.13 for Python 2.7 on Ubuntu 16.04? as suggested by #pyan, which solved my problem.
abhigenie92#ubuntu:~/Desktop/pygame-1.9.1release$ which python
/home/abhigenie92/anaconda/bin/python
abhigenie92#ubuntu:~/Desktop/pygame-1.9.1release$ sudo apt-get install python-pygame
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-pygame is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 224 not upgraded.
abhigenie92#ubuntu:~/Desktop/pygame-1.9.1release$ python
Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 17:02:03)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygame
What is happening above? It seems to not install for anaconda. But it is directing to the right from path.
You are installing things into the system Python. You need to install into the Anaconda Python, using pip install pygame (note that sudo pip is likely going to use the system Python again, and using sudo with the Anaconda Python is not recommended anyway).
I have two versions of Python installed on my centOS server.
[ethan#demo ~]$ python2.6 --version
Python 2.6.6
[ehtan#demo ~]$ python --version
Python 2.7.3
The older version (2.6) is required by some essential centOS packages so I can't remove it.
When I install packages using pip, they are being installed in Python 2.6. But instead I want them to be installed to Python 2.7.
How can I change this behaviour?
For example, here is what happened when I tried installing Wand
[ethan#demo ~]$ pip install Wand
Requirement already satisfied (use --upgrade to upgrade): Wand in /usr/lib/python2.6/site-packages
Cleaning up...
[ethan#demo ~]$ python2.6
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wand
>>> exit()
[ethan#demo ~]$ python
Python 2.7.3 (default, Oct 11 2013, 15:59:28)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wand
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named wand
>>> exit()
Edit
I found this answer but it didn't work for me https://stackoverflow.com/a/4910393/3384340
You need to install pip for each python version separately.
In order to install pip for Python2.7, run
sudo easy_install-2.7 pip
Use pip-2.7 to install Wand
sudo pip-2.7 install Wand