how could we install opencv on anaconda? - python

I tried to install OpenCV on Anaconda
pip install cv2
pip install opencv
conda install opencv
conda install -c https://conda.binstar.org/jjhelmus opencv
(refered here Anaconda doesn't find module cv2)
but all failed. Does anybody know how to install this?

Run the following command:
conda install -c https://conda.binstar.org/menpo opencv
I realized that opencv3 is also available now, run the following command:
conda install -c https://conda.binstar.org/menpo opencv3
Edit on Aug 18, 2016:
You may like to add the "menpo" channel permanently by:
conda config --add channels menpo
And then opencv can be installed by:
conda install opencv(or opencv3)
Edit on Aug 14, 2017:
"clinicalgraphics" channel provides relatively newer vtk version for very recent python3
conda install -c clinicalgraphics vtk

I guess
http://answers.opencv.org/question/17536/install-opencv-for-anaconda-ipython/
it would be an answer
If you compile OpenCV from source, and Anaconda is your default python interpretor
(CMake rule PYTHON_PACKAGES_PATH = C:\Anaconda\Lib\site-packages),
then the install rule will copy cv2.pyd to C:\Anaconda\Lib\site-packages.
Otherwise, you could do it manually, and make sure OpenCV libs are in the PATH.
Still I don't know what is CMake rule(?) and "install rule".

Firstly go to your anaconda folder. The path in my case was -
C:\Users.....\Anaconda3 . Then go to the Scripts folder.
Open this link- http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv .
Download this file - opencv_python-3.2.0-cp36-cp36m-win_amd64.whl from the link and copy paste it into your Scripts folder inside Anaconda3 folder.
Now go to spyder and type this,
import cv2
If everything works out it wont show any error and congrats you just installed it successfully.

Anaconda Python OpenCV-----------------
Remove all previous/current (if any) python installation
Install Anaconda and add anaconda to PATH(Envirnoment variables:: Adavanced system setting->Environment variables->under system variables go to variable PATHand click edit to add new envirnomental variables)
(During installation check box involve PATH)
Open anaconda prompt with admin access. Type and enter:-
conda update --all
conda install -c conda-forge opencv (for opencv)
conda install spyder=4.0.0 (spyder updation)
conda update python (for python updation)

Related

How to use egg to install scikit-image?

I am stuck on this installation of scikit-image (aka skimage). I tried multiple ways:
Installation from a git hub folder (using the requirements.txt)
Installation from a whl file
Installation with pip install scikit-image
All three trials failed during the import: import skimage
ImportError: cannot import name 'geometry'
It seems that scikit-image has not been built correctly.
Your install of scikit-image appears to be broken.
Try re-installing the package following the instructions at:
https://scikit-image.org/docs/stable/install.html
I went through internet but did not find solutions besides the ones above.
Does anyone went through that before?
One possibility seems to be to pip install with -egg, but I found that for Mac rather than Windows.
EDIT:
Hi everyone, so I found a solution but this is kind of very hard and I still don't understand why it did not work before.
I just:
uninstall anaconda
uninstall python
install python (3.8)
install Anaconda (I have trouble with Spyder now^^)
If you want to code for computer vision/Image processing/machine learning tasks, then it can be done in pycharm with conda environment very easily. There is no need to install python separately to run Anaconda.
First, download and install pycharm. Next, If you use windows then download Anaconda 64 bit python 3.7 version from here,
https://www.anaconda.com/distribution/#windows
You can find some details about managing environment and helpful links here,
How to create some environments for tensorflow in anaconda?
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
Create a conda environment first using Anaconda Prompt command line,
conda create -n cvenv python=3.7
Now activate that environment using. By default base is activated.
conda activate cvenv
Next, install the packages you want,
conda install -c conda-forge scikit-learn
conda install -c conda-forge scikit-image
conda install -c conda-forge pillow
conda install -c conda-forge opencv
I use conda-forge packages as they are more recent. Finally, open pycharm and create a new project by selecting existing python interpreter in conda environment. If none exists then select,
Browse > Add Python Interpreter > Conda Environment > Interpreter > Browse > Anaconda3 installation folder > envs folder > cvenv folder > Python.exe
You can test by creating a python file and writing import skimage.

conda environment has module installed but it does not import [duplicate]

Just installed a package through anaconda (conda install graphviz), but ipython wouldn't find it.
I can see a graphviz folder in C:\Users\username\Anaconda\pkgs
But there's nothing in: C:\Users\username\Anaconda\Lib\site-packages
The graphviz conda package is no Python package. It simply puts the graphviz files into your virtual env's Library/ directory. Look e.g. for dot.exe in the Library/bin/ directory.
To install the graphviz Python package, you can use pip:
conda install pip and pip install graphviz.
Always prefer conda packages if they are available over pip packages. Search for the package you need (conda search pkgxy) and then install it (conda install pkgxy). If it is not available, you can always build your own conda packages or you can try anaconda.org for user-built packages.
Update Nov 25, 2018: There exists now a python-graphviz package at Anaconda.org which contains the Python interface for the graphviz tool. Simply install it with conda install python-graphviz.
(Thanks to wedran and g-kaklam for posting this solution and to endolith for notifying me).
Update May 26, 2022: According to the pygraphviz website, the conda-forge channel should be used: conda install -c conda-forge pygraphviz (thanks to ian-thompson)
On conda:
First install
conda install graphviz
Then the python-library for graphviz python-graphviz
gv_python is a dynamically loaded extension for python that provides
access to the graph facilities of graphviz.
conda install python-graphviz
There is also pydot package, which can parse and dump into DOT language, used by GraphViz
conda install pydot
for me the problem was solved by installing another supportive package.
so I installed graphviz package through anaconda
then I failed to import it
after that I installed a second package named python-graphviz also through anaconda
then I succeeded in importing graphviz module into my code
I hope this will help someone :)
You can actually install both packages at the same time. For me:
conda install -c anaconda graphviz python-graphviz
did the trick.
To install graphviz,
conda install -c anaconda graphviz
pip install graphviz
If conda command not found. Follow these:
export PATH=~/anaconda/bin:$PATH
conda --version # to check your conda version
Difference between conda and pip installation,refer this stackoverflow answer
I have followed the following steps and it worked fine for me.
1 . Download and install graphviz-2.38.msi from
https://graphviz.gitlab.io/_pages/Download/Download_windows.html
2 . Set the path variable
(a) Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit
(b) add 'C:\Program Files (x86)\Graphviz2.38\bin'
Graphviz is evidently included in Anaconda so as to be used with pydot or pydot-ng (both of which are included in Anaconda). You may want to consider using one of those instead of the 'graphviz' Python module.
For ubuntu users I recommend this way:
sudo apt-get install -y graphviz libgraphviz-dev
Remeber! If you are using jupyter notebook, please restart it after the installing. That's work for me.
Because the condition before is a static variate as below:
Check if tensorflow is activated in your terminal
first deactivate it using
conda deactivate
then use the command
conda install python-graphviz
and then install
conda install graphviz
this is solution for UBUNTU USERS :) CHEERS :)
This command works officially for python:
conda install -c conda-forge python-graphviz
run this:
conda install python-graphviz
I am using anaconda for the same.
I installed graphviz using conda install graphviz in anaconda prompt.
and then installed pip install graphviz in the same command prompt. It worked for me.
I tried this way and worked for me.
conda install -c anaconda graphviz
pip install graphviz

Unable to install OpenCV 3.2 in Anaconda 4.3

Tried the following steps
conda install -c menpo opencv3=3.2.0 ..
Fetching package metadata....An unexpected error has occurred
Did some internet search and used conda config --set ssl_verify=False
Then tried doing conda update -all and conda update pyopenssl but no luck
even remove certifidoes not work ...gives the same error...infact any update / install attempt gives the same result.
I have NOT set my PYTHONHOME or PYTHONPATH
Followin are the screen shots of my current conda settings and the update/install error. Platform : Windows 8.1
If there is any other method to install OpenCV 3.2 in Anaconda environment please mention it
EDIT : PROBLEM SOLVED
Open Anaconda terminal
Navigate to the folder in Anaconda main folder which contains Python Scripts
Download the un-offical opencv + contrib binaries from here
In the Anaconda terminal do pip install
`
For anaconda running python 3.7, you can use
conda install py-opencv=3.4.2
The menpo file page shows only OpenCV 3.2.0 for Python 2.7/3.4/3.5 on linux-64 platform is available.
You can try this OpenCV 3.2.0 binary in github if your Windows is 64-bit and with Python 2.7.
See this https://stackoverflow.com/questions/42310099 for more informtion.
Also, you can go into your Anaconda environment and run one of the following for OpenCV 3.4.4:
conda install -c conda-forge opencv
conda install -c conda-forge/label/gcc7 opencv
conda install -c conda-forge/label/broken opencv
conda install -c conda-forge/label/cf201901 opencv
I was able to create a new environment using the anaconda navigator with python 3.5. It works for me in that environment.

OpenCV not working properly with python on Linux with anaconda. Getting error that cv2.imshow() is not implemented

This is the exact error that I am getting. My OS is Ubuntu 16.10.
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp, line 545
Traceback (most recent call last):
File "untitled.py", line 7, in
cv2.imshow('image',img)
cv2.error: /feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp:545: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage
my code is:
import numpy as np
import cv2
# Load an color image in grayscale
img = cv2.imread('0002.png',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
0002.png is an image in the same directory as the program.
I first installed anaconda with python 3.5, then I installed opencv by using the command
conda install -c conda-forge opencv
I installed libgtk2.0-dev just as the error said to but I still get the same error.
Any help would be much appreciated. I've been trying to solve this for several hours.
1.The easiest way:
conda remove opencv
conda update conda
conda install --channel menpo opencv
or (for OpenCV 3.1) :
conda install -c menpo opencv3
2.And if u don't want to do this, you can try to use matplotlib .
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('img.jpg',0)
plt.imshow(img, cmap='gray')
plt.show()
3.Or try to build library by your own with option WITH_GTK=ON , or smth like that.
Update - 18th Jun 2019
I got this error on my Ubuntu(18.04.1 LTS) system for openCV 3.4.2, as the method call to cv2.imshow was failing. I am using anaconda. Just the below 2 steps helped me resolve:
conda remove opencv
conda install -c conda-forge opencv=4.1.0
If you are using pip, you can try
pip install opencv-contrib-python
I have had to deal with this issue a couple of times, this is what has worked consistently thus far:
conda remove opencv
conda install -c menpo opencv
pip install --upgrade pip
pip install opencv-contrib-python
πŸš€ Working method (πŸ‘¨β€πŸ”¬ tested on April 19, 2019)
🐞 These error happen because of conda.
🏹 Open Anaconda Prompt and remove conda opencv if installed
πŸ‘¨β€πŸ’» conda remove opencv
πŸ“’ If you have conda env, firstly activate it conda activate <your_env_name>
⏬ After install opencv via pip (click here to offical info)
πŸ‘¨β€πŸ’» pip install opencv-contrib-python
πŸ“’ if pip haven't installed, use conda install pip command.
If you installed OpenCV using the opencv-python pip package at any point in time, be aware of the following note, taken from https://pypi.python.org/pypi/opencv-python
IMPORTANT NOTE
MacOS and Linux wheels have currently some limitations:
video related functionality is not supported (not compiled with FFmpeg)
for example cv2.imshow() will not work (not compiled with GTK+ 2.x or Carbon support)
Also note that to install from another source, first you must remove the opencv-python package
For me (Arch Linux, Anaconda with Python 3.6), installing from the suggested channels menpo or loopbio did not change anything. My solution (see related question) was to
install pkg-config (sudo pacman -Syu pkg-config),
remove opencv from the environment (conda remove opencv) and
re-install opencv from the conda-forge channel (conda install -c conda-forge opencv)
conda list now returns opencv 3.3.0 py36_blas_openblas_203 [blas_openblas] conda-forgeand all windows launched using cv2 are working fine.
I followed this tutorial (OpenCV GTK+2.x error) and did the following. It worked for me :
install the packages : libgtk2.0-dev and pkg-config
cd to your opencv directory
mkdir Release
cd Release
Run the command : cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_GTK=ON -D WITH_OPENGL=ON ..
make
sudo make install
Notice that it is complaining for libgtk2.0-dev and pkg-config. Here is the solution. Uninstall your existing openCV installation.
conda remove opencv3
Install these packages before installing opencv-
conda install gtk2 pkg-config
Now install opencv from menpo
conda install -c https://conda.anaconda.org/menpo opencv3
If you are running inside docker then you may get this error.Solution uninstall current and install the headless one
pip install opencv-python==3.4.5.20
pip install opencv-contrib-python==3.4.5.20
If you are writing to the image and displaying it, you may need the following
apt-get update && apt-get install -y libglib2.0-0 libsm6 libxext6 libxrender1
And if you are wondering how to get the display from Docker, it is possible via X11 in your host
My ubuntu 18.04 machine is running at AWS.
What helped me was (link):
pip uninstall opencv-python
pip install opencv-python==4.1.2.30
Afterwards I got the error: " : cannot connect to X server "
Finally, I managed to make it work by installing MobaXTerm (reference here).
FYI:
I connect to AWS with WinSCP. If you connect to AWS via something like WinSCP, the MobaXTerm interface lets you connect to the "WinSCP temporary session" if you click at "Sessions", which is very convenient. The session screen basically replaces the console but allows to display the image via a pop-up window.
In case you also experience the error ASSERT: β€œfalse” in file qasciikey.cpp, line 501 once cv.imshow() or similar is executed, go to the MobaXTerm interface, click Settings -> Configuration -> X11, uncheck "Unix-compatible keyboard" (reference here).
I used pip to install opencv-python. (https://pypi.org/project/opencv-python/)
1) Remove the opencv package from conda:
>> conda remove opencv
2) To your env.yml file add this:
...
dependencies:
- numpy
- pytest
...
- pip:
- opencv-python
Remove opencv from anaconda=
conda remove opencv
Then, reinstall opencv using pip:
pip install opencv
This is working for me.
My Envirment is Win10, and I added the anaconda path to the environment variables's PATH’,the cv2.imshow worked
C:\Users\user\Anaconda3
C:\Users\user\Anaconda3\Scripts
Then restart the windows
Although this is already answered, for me conda-forge solution worked with a hack.
My workstation is a centos 6 machine, and I use conda virtual environment (anaconda 2). Create an environment
conda create --name test python=2.7
and then activate it
conda activate test
Now install opencv from conda-forge
conda install -c conda-forge opencv
Now install matplotlib in this environment (and this is hack 1)
conda install matplotlib
Let's check now imshow works or not. In a terminal, activate test environment and start python. In the interpreter, do
import cv2
import matplotlib.pyplot as plt # hack 2
img = cv2.imread('your_image_file',0)
cv2.imshow('image',img)
This should pop up a window showing image. I did not further research how this solved the case.
Note 1: You may see some error related to xkb, then in your .bashrc file add
export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb
Note 2: You may see some error related to XDG_RUNTIME_DIR, then in your .bashrc file also add
export XDG_RUNTIME_DIR=.tmp/myruntime
and define myruntime by mkdir -p .tmp/myruntime
For my system (Ubuntu 18.04) the following was working.
First:
sudo apt-get update -y
sudo apt-get install -y libgtk2.0-dev
conda create -n py35 python=3.5
conda activate py35
Then configure the environment
pip install Cython
pip install scikit-build
conda install -c anaconda cmake
pip install dlib
pip install face_recognition
pip install imutils
And finally:
pip install opencv-contrib-python
Easy with Ubuntu 18.04. It works for me:
Remove opencv-python:
pip3 uninstall opencv-python
And then re-install opencv-python:
pip3 install opencv-python
Issue was resolved.
I was able to fix it by installing a previous version of opencv-contrib-python.
I'm using Ubuntu 18

Anaconda OpenCV Arch Linux libselinux.so error

I have installed Anaconda 64 bit on a relatively fresh install of Arch.
I followed the instructions here to set up a virtual environment for opencv:
conda create -n opencv numpy scipy scikit-learn matplotlib python=3
source activate opencv
conda install -c https://conda.binstar.org/menpo opencv3
When I run "import cv2" on the activated virtual environment I get:
ImportError: libselinux.so.1: cannot open shared object file: No such file or directory
I have no clue how to fix this - do I need to make kernel changes?
Thanks for any help.
Fixed with installing the libselinux package in the AUR:
yaourt -S libselinux
I now have another problem:
ImportError: /usr/lib/libpangoft2-1.0.so.0: undefined symbol: FcWeightToOpenType
Solved as in issue 368
conda install -c asmeurer pango
To solve this problem you can install the missing package with:
yaourt -S libselinux

Categories

Resources