Sign in

I had used pyenv to manage several Python versions. However, on macOS Big Sur, it didn’t work well. Here, I introduce a way to install Python 3.9.1 using installer which can be downloaded from official site.

Video

Install Python using installer

Visit official site and download installer. In my case, I chose macOS 64-bit Intel Installer.

Install the Python using downloaded installer. That’s it. Now you can use python3.9 and pip3.9 on terminal.

Upgrade pip3.9

Upgrade pip3.9 by the following command:

pip3.9 install --upgrade pip

(optional) Install pipenv

Install pipenv by the following command:

pip3.9 install --user pipenv

(optional) Install poetry

Alternatively, you can use poetry. Install poetry by the following command:


In this post, I introduce a way for reading images using opencv-python . Suppose that the Python project will be managed by Pipenv (see my previous post).

Installation

You can install opencv-python using pip:

pipenv install opencv-python

If you try to build official software, you should specify the version of package. The version can be found on PyPI. The latest version of opencv-python is 4.5.1.48 at 2021/01/05.

You can specify the version like this:

pipenv install opencv-python~=4.5.1.48

Reading image by cv2.imread

You can read images by the function cv2.imread like this:

import cv2

image = cv2.imread('/path/to/imagefile')

Change /path/to/imagefile to the path of your image. After…


Image classifier can be easily built by using deep learning especially Convolutional Neural Network (CNN). However, you can simply implement image classifier using traditional classifiers. In this post, I introduce how to build image classifier not using Deep Learning. I will not use mathematical formula. Please try to understand the overview intuitively.

Video

Feature extraction

Feature extraction part refers to CNN. The important concepts are window and stride. Let us denote horizontal window as wx, verticalwindow as wy, horizontal stride as sx, and vertical stride as sy.

Suppose you have a image like this:

Next, consider a rectangle (called window) whose width…


In this post, I introduce several ways to get directories and files in Python.

Suppose that the project directory is the following structure;

data/
train/
1.txt
2.txt
3.txt
test/
1.txt
2.txt
3.txt

and, you are ../data .

os.listdir

You can list directories using os.listdir . Example usage is below:

import os

in_dir = './data'
for dirname in os.listdir(in_dir):
print(dirname)

By running the code, you can see the output like this:

train
test

Note that you can only list the directories. If you need the path to the directories, the code should be like this:

import os

in_dir = './data'
for dirname in os.listdir(in_dir)…

In order to make writing codes fast, completion is quite important. In this post, I introduce the way to enable completion in Visual Studio Code (vscode) for Pipenv project.

If you create Python project by following my previous post, .venv/ is created at the project root. You can enable completion by let vscode see this .venv/ . To do so, Select Code -> Preferences -> Settings , and enter python venv path` to search bar, then set .venv like this:

Code -> Preferences -> Settings

Whenever you edit Python project using vscode, open vscode by the command like this:

cd project-name
pipenv shell
code .

The setting for the completion is done. Thanks for reading.

This post is linked to my Youtube channel:https://www.youtube.com/channel/UC-SHOllZQsQFCsbL3BvP1rA

The content might be updated in the future.


In this post, I introduce how to start Python project.

pyenv

Install and setup pyenv by following the instruction below,

On macOS, using homebrew is easy, but I use git clone .

After installation and setup, install some versions of Python. In this post, I use Python 3.9.1.

pyenv install 3.9.1

Pipenv

pipenv is a software for package management and virtual environment.

Installation

Install pipenv by the following instruction below,

After installation, add the code below to the setting file of shell (e.g. .bashrc or .zshrc) to create .venv/ under the project root.

PIPENV_VENV_IN_PROJECT=true

Starting Python project

Let us start Python project by the…

pillyshi

Machine Learning Engineer / Youtube streamer. I will share useful information about engineering.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store