Error in installing OpenCV with python (MAC OSX) and PyCharm IDE - python

I want to install the OpenCV to then include it in PyCharm on my Mac, and
I have started with the terminal following this guideline: click here
the problem is when I follow the third step and write this code:
$ brew install opencv3 --with-contrib --with-python3
this error has shown:
Error: invalid option: --with-contrib
Of course I have installed also the PyCharm IDE for python and the latest verson of python (3.7) to be knowledged
please if you can help me I will appreciate that
This problem was solved! thank you

According to the formula, opencv3 no longer requires these flags.
CMake flags
-DOPENCV_ENABLE_NONFREE=ON
-DOPENCV_EXTRA_MODULES_PATH=#{buildpath}/opencv_contrib/modules
enable support for contrib modules.
-DBUILD_opencv_python2=ON
-DBUILD_opencv_python3=ON
-DPYTHON2_EXECUTABLE=#{which "python"}
-DPYTHON2_LIBRARY=#{py2_lib}/libpython2.7.dylib
-DPYTHON2_INCLUDE_DIR=#{py2_prefix}/include/python2.7
-DPYTHON3_EXECUTABLE=#{which "python3"}
-DPYTHON3_LIBRARY=#{py3_config}/libpython#{py3_version}.dylib
-DPYTHON3_INCLUDE_DIR=#{py3_include}
provide support for Python3 as well as Python2.
Just run
brew install opencv3

Related

Import "cv2" could not be resolved

I've installed python and opencv by using the correct commands in the cmd, but when I type in 'import cv2' in a python then I get the error in visual studio code and I can't find any solution online how to fix this
Import "cv2" could not be resolved Pylance (reportMissingImports)
More of the error in the terminal
ModuleNotFoundError: No module named 'cv2'
It just happened to me and I solved it installing both opencv-python and opencv-python-headless with pip and reloading the Visual Studio Code window right after it.
To install the needed packages, just run this command in the terminal:
$ pip install opencv-python opencv-python-headless
Make sure that its using the correct version of Python; e.g., I installed Python from the windows store, which is working:
However, if I use another one, it does not work:
I noticed that Visual Studio does not support the latest Python 3.8, so I had to use PyCharm as an IDE.
I had a similar issue so I installed opencv-python-headless (install opencv-python if not earlier) and reloaded the VScode window.
pip install opencv-python-headless
However, some methods like imshow() kept failing:
cv2.error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa 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'
This was resolved by installing opencv-contrib-python. You can install it by running the following code in your terminal:
pip install opencv-contrib-python
In your terminal (cmd if Windows) run the following (make sure that you're on the current working environment):
pip install opencv-python
then:
pip install opencv-python-headless
I just uninstalled the older python version and installed a new one again. That is probably the simplest and the most hassle-free one in my mind. Stick to version 3.8.8, that should do the trick. Also no worries about maintaining multiple versions of python in the system. It is indeed true that the lack of support from VS is causing this issue.
I am on a mac and struggle with this and this is the best way to do it, when ur in your .py file, on the lower left part of your vscode windown u will see the version of python you are using, click that and try different versions until your open cv command works, in my case, 3.8.8 worked for me.

I can't install python with home-brew, because of no bottle available

As the question title says, facing the below error. using Mac.
how can I install python with homebrew again not with building from source?
Even though I deleted python#3.8 from homebrew, when I type which python3 there's still python3 here /usr/local/bin/python3. is this meaning that I haven't used python installed from homebrew?.
python#3.8: no bottle available!
You can try to install from source with e.g.
brew install --build-from-source python#3.8
Please note building from source is unsupported. You will encounter build
failures with some formulae. If you experience any issues please create pull
requests instead of asking for help on Homebrew's GitHub, Twitter or any other
official channels.
homebrew only supports the latest three macOS (which are mojave, catalina, and big_sur), the bottles are listed in here. You can also see Apple Silicon version there as well.
So if you are on the latest homebrew-core, you can only install from bottles with those three OSX.
I encountered the same issue. I ran xcode-select --install. This installed the CLT for my mac. Then I was able to install python3 by running xcode-select --install

MacOS Catalina comes with Python 3.7.3, need to upgrade

I recently upgraded to macOS Catalina and it seems to come with Python 3.7.3. All of my packages have come from the PIP installed with Python 3.7.3.
I have installed Python 3.7.7 (the newest version available on Homebrew), but it gives an error when linking. It tells me to run brew link python3, and when I do, it says
Linking /usr/local/Cellar/python/3.7.7...
Error: Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
rm '/usr/local/bin/2to3'
To force the link and overwrite all conflicting files:
brew link --overwrite python
To list all files that would be deleted:
brew link --overwrite --dry-run python
Previously, I accidentally uninstalled Python 3.7.3, which many people have recommended against because it is not a good idea to uninstall the macOS bundled Python and may cause issues with the operating system. I had lost all of the packages installed using PIP, and I had to restore my computer using my Time Machine backup to avoid issues with my operating system.
How can I make the newest version of Python (3.7.7) the default, and "transfer" my packages from PIP into the newest version of Python (if that is even required) and fix my Python installation?
A Python installation of 3.7.3 came with Xcode, so all I had to do was delete the app Xcode, and I ran a fresh installation of Python using Brew.
yes you are right. New MacOs built in python3.7.3 in system and it comes from xcode, u dont't have to uninstall xcode
all you need to do is remove /lib/commandlinetools/freamwork/python3.7.3.
and install newest python with brew.
run python3 --version and pip3 --version they all newest from brew

install caffe on mac " Error: invalid option: --with-python"

when I install the caffe on mac according to :
Remaining dependencies, with / without Python
# with Python pycaffe needs dependencies built from source
brew install --build-from-source --with-python -vd protobuf
brew install --build-from-source -vd boost boost-python
# without Python the usual installation suffices
brew install protobuf boost
I paste the second one to the terminal, and result is:
Error: invalid option: --with-python
I can not find any similar problem, can some help me with that?
Options have been removed from Homebrew core formulas and only exist in taps now. See this GitHub issue. Building with python has been made the default behavior for protobuf.
See the formula, lines 49-51.
chdir "python" do
system "python3", *Language::Python.setup_install_args(libexec),
"--cpp_implementation"
So it should be fine to run
brew install --build-from-source -vd protobuf

Installing opencv on Windows 10 with python 3.6 and anaconda 3.6

How to install opencv with python 3.6 and anaconda 3.6?
I tried conda install -c https://conda.binstar.org/menpo opencv3
but i get the following error:
UnsatisfiableError: The following specifications were found to be in conflict:
- opencv3 -> python 2.7*
- python 3.6*
Use "conda info <package>" to see the dependencies for each package.
I am using Windows 10 64-bit, with python 3.6, and anaconda 3.6 installed.
Is it even available for python3.6 at the moment or should i rollback my python version to 3.5.*?
search anaconda prompt
open and run the command.
> pip install opencv-python
this single command help's you to install opencv easily.
you can take help from the video link below.
video link
From menpo file page, it shows that the OpenCV 3.2 binary there are only for Python 2.7/3.4/3.5 and on linux-64 platform
You may go to the this site to get the exact version you need.
opencv_python‑3.2.0‑cp36‑cp36m‑win_amd64.whl is the basic one.
opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl is the one
with opencv-contrib modules such as the text module for binding to tesseract OCR engine and many others.
Both binary are for OpenCV 3.2 with Python 3.6 binding for Windows 64-bit. To install it, 1) download the binary to local drive, 2) open your Anaconda command prompt and 3) type the command below in the directory the binary locates.
pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
Hope this help.
Update on 2018-02-22:
OpenCV 3.4.0 wheel files are now available in the unofficial site and replaced OpenCV 3.3.0
Update on 2019-01-30:
OpenCV 4.0.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.
I managed to get it working by doing the following:
Download and install python3.6 from official python site
https://www.python.org/downloads/release/python-360/
Download and install Anaconda 4.4.0 from the official anaconda site
https://www.continuum.io/downloads
Open command line and run:
pip install opencv-python
Open command line and run:
pip install opencv-contrib-python
I am using Windows 10 and it worked for me.
It's pretty simple..
Install Anaconda 3.6. Check anaconda is added to System Variable Path.
Open CMD and type conda install -c conda-forge opencv.
This will install latest OpenCV version available (3.6).
Open IDE editor and try import cv2.
It will probably don't work...don't worry.
You have to add cv2 command to editor.
For Eclipse (with PyDev):
Create firs a project and then do the following:
For PyCharm:
cv2 module probably won't work. Go to the Anaconda folder/Lib/site-packages/cv2 and copy the file cv2.cp36-win_amd64.pyd to the site-packages folder. Rename it cv2.pyd
Now try to write a command... cv2.imread(). If auto-completition don't work, try cv2.cv2.imread().
This will work for sure.
I am using Python 3.6.2 and Anaconda 4.3.23 (It should also work with your case).
I did the following:
Download the Numpy version corresponding to your Python installation from here. In my case, I’ve used numpy-1.13.1+mkl-cp36-cp36m-win_amd64.whl
Download the OpenCV version corresponding to your Python installation from here. In my case, I’ve used opencv_python-3.3.0-cp36-cp36m-win_amd64.whl
Now go to the folder where you downloaded these files and run the following:
pip install numpy-1.13.1+mkl-cp36-cp36m-win_amd64.whl
pip install opencv_python-3.3.0-cp36-cp36m-win_amd64.whl
Note the Successfully installed … message after each command.
At this point, you should be able to play with OpenCV and Python. Let’s try a small test first. Start the Python interpreter or Jupyter Notebook and write:
import cv2
print(cv2.__version__)
If everything was correctly installed, you should see the version number of your OpenCV install, in my case this was 3.3.0.
I see you found a solution but this may be helpful for others. The package is not available for Python 3.6. You can check this by going to that package channel on anaconda.org and selecting the files tab. You will see the package tarballs with the Python version listed as py27, py34, py35,etc. This is a good way to check for Python versions of a specific package.
You can also run the following to see the package versions and Python versions available for your OS from the Anaconda channel:
conda search <package_name>
Or to search a particular channel and package you can do this:
conda search -c <channel_name> <package_name>
As of March 2018, OpenCV 3.4 can be installed directly from conda-forge or anaconda in Windows/OSX/Linux for Python 3.6
conda install -c conda-forge opencv
or
conda install -c anaconda opencv
Using:
conda install -c conda-forge opencv
worked for me
If you have installed anaconda then you should uninstall it, then try
pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl
It worked for me.
Thank You.
I am using python 3.6 and the following worked for me:
Download and install opencv (Win pack) on your computer from the official website:
https://opencv.org/releases.html (I took version 3.4.2)
Go to the website of Christoph Gohlke and download the wheel file corresponding to your system. (I took opencv_python-3.4.2-cp36-cp36m-win_amd64.whl)
As mentioned on the website of Christoph Gohlke, make sure you installed 'numpy1.14' & 'mkl' package. Also make sure you use pip with version 9 or newer.
Start the 'Anaconda Prompt'
Change the directory in the 'Anaconda Prompt' to the folder where you downloaded the wheel file from Gohlke's website (via the MS-DOS command 'cd').
In the 'Anaconda Prompt' type 'pip install opencv_python-3.4.2-cp36-cp36m-win_amd64.whl') (change the name of the wheel file accordingly).
When starting spyder, test your installation as follows:
import cv2
print(cv2.__version__)
If the version is printed in the console (in my case 3.4.2), your installation was successful.
IMPORTANT REMARK:
If you created a dedicated environment within Anaconda (in my case 'py36'), make sure you installed spyder for this dedicated environment ('conda install spyder'). If not, your installation of opencv will not be recognised within the environment you are working in. Maybe this is obvious and straightforward but in my case I struggled to find this solution.
First Download Anaconda Python 3.6 from official site. After installing anaconda, simply open command prompt and type following statement and press enter of course -
conda install -c conda-forge opencv
It may take some time. After the completion, check your conda packages by typing conda list - opencv should be there.
However, Before proceed to install opencv, you can check whether opencv for python 3.6 is available or not. We can check it by typing conda info opencv in command prompt and press enter of course, you'll see following -
opencv 3.3.1 py36h20b85fd_1
---------------------------
file name : opencv-3.3.1-py36h20b85fd_1.tar.bz2
name : opencv
version : 3.3.1
build string: py36h20b85fd_1
build number: 1
channel : https://repo.anaconda.com/pkgs/main/win-64
size : 96.7 MB
arch : None
constrains : ()
license : BSD 3-clause
license_family: BSD
md5 : e65c68524073445511ace8ade7ae3641
platform : None
subdir : win-64
timestamp : 1512689066576
url : https://repo.anaconda.com/pkgs/main/win-64/opencv-3.3.1-py36h20b85fd_1.tar.bz2
dependencies:
jpeg >=9b,<10a
libpng >=1.6.32,<1.7.0a0
libtiff >=4.0.9,<5.0a0
numpy >=1.11.3,<2.0a0
python >=3.6,<3.7.0a0
vc 14.*
zlib >=1.2.11,<1.3.0a0
By this we can also get ensure that opencv 3.3.1 py36h20b85fd_1 is available. And this is available for python 3.6
I think this way is straight forward. Just install anaconda from official page and follow the image.
Using Anaconda3's package manager directly will be more reliable and cross-platform:
conda install opencv

Categories