As I mentioned in this article, matplotlib is not supported with miniconda. To resolve the issue, I read through Python 3.7 documentation and realized using Virtual Environment would be a good way to handle the conflicts.
The following tutorial is tested on macOS 10.14 Mojave.
To create a python Virtual Environment, use the following command, where env_name is the name of the environment that you want to create. The env_name folder is created if there’s no such env_name called that before.
$ python3 -m venv env_name
Activate the virtual environment by running
$ source activate
Now you can check your python version by running
$ python --version
Now
$ pip install opencv-python
$ pip install matplotlib
$ pip install numpy
After the installation, it should be safe for you to import cv2 and process your images with opencv.
$ python
>>> import cv2
# To check your cv2 version
>>> cv2.__version__
'4.0.0'
Basic Operations
To create a .py file
$ touch example.py
To edit a file with idle or sublime(To open a file with sublime in terminal requires extra configuration)
$ idle3 example.py
$ sublime example.py
To execute you code:
$ pythonw example.py
Pycharm is more friendly
If you are a Jetbrains fan like me, you may want to use Pycharm. Actually, it is more friendly, the only thing you need to do is to open the working directory in the IDE, and then run
$ source activate
inside the terminal below the editor directly.