Install OpenCV correctly on macOS Sierra - python-3.x

I am running on macOS Sierra and I have python 3.5.2 installed on my system.
Now I want to use opencv with python. So here is what I did :-
Installed XCode
Installed CMAKE
Downloaded opencv 3.2 and extracted to my Document directory.
Created a new directory called build inside my opencv directory in Document (obtained from step 3)
Opened CMAKE and configured it to run with source as the opencv directory in Document and target as the build directory within it.
Ran the "make" command from "build" directory
Ran "sudo make install"
All these steps completed successfully. Now I go to IDLE 3.5.2 shell and do "import cv2" and then I get the error "ImportError: No module named cv2"
I tried other solutions like pip3 install opencv-python. It removes the import error but I cannot use this because it doesn't support cv2.imshow() (I kind of need it).
Please help me install and configure opencv correctly.

If you are still stuck you can try by brew, did a fresh install some weeks ago and here is the full process.
As opencv cant support python2 & 3 by default install (read further)
brew edit opencv3
in formula edit this part:
if build.with?("python3") && build.with?("python")
# Opencv3 Does not support building both Python 2 and 3 versions
odie "opencv3: Does not support building both Python 2 and 3 wrappers"
end
by commenting it out ( # at start line).
then:
brew reinstall opencv3 --with-contrib --with-python3 --HEAD
if you have cmake.downloader error you need to edit the brew call and remove the --HEAD flag.
This error is just du to a file missing in the head repository (might be fix soon or not).
Also check your site-package/python version

One issue I found was with then name of the .so library created on install. Try renaming it to cv2.so instead of the longer name it starts with.
On my system it's found here:
/usr/local/opt/opencv/lib/python3.6/site-packages
Also, you can confirm that the above site-packages folder is accessible via sys.path.
>>> import sys
>>> sys.path
If not, you can create a .pth file in one of those directories that contains simply the path name of your site-packages folder above.

Related

How to install wheel package of tensorRT for tensorflow on Windows 10?

From NVIDIA tensorRT documentation I have completed the first 4 steps for zip file for windows.But Now I can't really understand the 5th and 6th step specially where I have to 3 things to get it work for "tensorFlow". I can't understand how to execute this line
python3 -m pip install <installpath>\graphsurgeon\graphsurgeon-0.4.5-py2.py3-none-any.whl
Here is the link: https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#installing-zip
P.S:I am very new to this world of machine learning and TensorFlow.
You need to open a terminal with a python environment.
Press Ctrl+r and type cmd+Enter to open a terminal. You can check if you have the correct Python version by running python --version.
More information about package installing can be found here:
https://packaging.python.org/tutorials/installing-packages/#requirements-for-installing-packages
For install command execution, replace <installpath> by the location, where you installed TensorRT, e.g., if you installed it in C:\Program Files\TensorRT use:
python3 -m pip install "C:\Program Files"\TensorRT\graphsurgeon\graphsurgeon-0.4.5-py2.py3-none-any.whl
This is described in 2) from your link:
Choose where you want to install TensorRT. The zip file will install
everything into a subdirectory called TensorRT-7.x.x.x. This new
subdirectory will be referred to as <installpath> in the steps below.

Correctly patching Python open source package without package clashing

I debated which Stackoverflow site this best fit but couldn't decide.
I'd like to contribute to an open-source project on Github, but I can't figure out how to prevent the stable version already installed on my machine and the development version I'd like to make a patch for from clashing on import.
The repository only suggests pip installing with the editable.
What I've done so far is: clone the repository locally, and then trying to import it in a Jupyter Notebook from the directory above. However, the Jupyter Notebook is referencing the stable version installed earlier with pip. I tried to append to sys.path the child directory holding the package but still the same issue. I can't seem to get relative imports working either. Do I need to uninstall the stable version?
Any tips are appreciated!
You'd use virtualenv for this. It will allow you to create an environment that is isolated from your system python and you can install the dev version of the library on it.
Basic usage (for Unix-like systems) is:
$ pip install virtualenv
$ virtualenv MY_ENV
$ cd MY_ENV
$ source bin/activate # activates the local python for this shell only
(MY_ENV)$ pip install <some-module> # installs to a local and isolated python
(MY_ENV)$ python ... # runs python in the local environment
(MY_ENV)$ deactivate # disable the isolated python
$

Python 3.7 altinstall and installing PIP: PyCharm: unix system

I decided to I wanted to test the newest version of Python. I downloaded from source and performed an altinstall so python3.7 (full) in located in usr/local/lib and its executable is # usr/local/bin. I thought an easy way to go about getting modules installed would be to select this executable as my Project Interpreter in PyCharm and use its package manager to install pip and whatnot. However, when I select 3.7 executable as the: Virtualenv Environment it will not allow me to hit 'ok'. Instead a warning at the bottom left of the window says:
Environment location directory is not empty
So I tried selecting the executable as the System Interpreter and it works to an extent. It allows me to hit ok but in the package manager window there is a yellow bar at the bottom that says:
Python packaging tools not found. Install packaging tools
So if I click the link it attempts an install (requires sudo) and then instead of installing, a warning box pops up:
Failed to install Python packaging tools:
ModuleNotFoundError: No moudle named'_ctypes'
So, how do I get PyCharm to use 3.7 s/t I can install modules for it?

How to install Python package when using Spyder

I have installed this python package called shuttle using git bash. It works fine when I am using it in git bash. But when I am trying to import shuttle from Spyder or even Jupyter Notebook, its showing error -
ImportError: No module named 'shuttle'
Can you please explain why I am seeing this error and how can I fix it ?
Update: What I realise from searching in google, pip install/spyder/anaconda all have different environment. Because I installed 'shuttle' using pip, Spyder doesn't know about it. So now the problem is how do I install the package in Spyder environment or how do I make Spyder recognise that 'Shuttle' is already installed ?
This is how I solved it:
1. Install the package via pip. In your case shuttle
2. Locate the directory where shuttle is installed. You can do that by opening terminal
python
import shuttle
shuttle #displays location of shuttle
3. Now add shuttle to /path/to/anaconda/lib/
reference post: Anaconda: Permanently include external packages (like in PYTHONPATH)

iPython on Win8 fails to install modules

Please bear with me the total novice of Python 3 and non native English speaker.
I'm using windows 8 in iPython notebook environment, and I have problem installing modules such as Jieba. If you go to its homepage, the English version is in the bottom (however, not as updated as the Chinese version). It says it supports Python 3 as well, so I tried using git as it suggested, but it gave me this (I successfully cloned it before).
Some other things I tried as well
Using cmd to run setup.py
Using pip3 (it's another module I failed to install)
Installing easy_install (same, couldn't install it)
Do I have to use other approaches to install modules cause I'm using iPython notebook? I'm so frustrated. I'm trying to do text mining on some Chinese texts but I struggle so much with this hurdle already.
You've already cloned Jieba into your home directory (~), which is why your second attempt at cloning failed. Enter the jieba directory, and run git pull to sync any changes from the master repo. You can then run python setup.py install in that directory to install the module.
To install pip on Windows, follow the instructions in this question.

Resources