02. Set Environment with virtual machine
02. Set Environment with virtual machine
Set Environment with virtual machine
Prerequisites
1
python
1. Why we set Environment with virtual machine
When we use library, sometimes the version is not support some functions or another issue. So we will use virtual machine with python.
1
python -m venv {name}
If you remove virtual machine
1
Remove-Item -Recurse -Force .\{name}
Activate virtual machine
1
{name}\Scripts\activate
1-1. on virtal machine
If you activate venv, we’re already in venv path like (venv-opencv) PS C:\Users\imjg0\Desktop\opencv-project>
First python version checking
1
2
python --version
python -m pip install --upgrade pip
Now you should install package you want on venv path.
1
pip install {package}
Other way (recommended)
Current install list regist on requirements.txt
1
pip freeze > requirements.txt
On requirements.txt, regist the list of package name
1
2
3
4
5
numpy==2.1.1
opencv-python==4.12.0.88
open3d==0.19.0
scipy
matplotlib
Install package listed
1
pip install -r requirements.txt
Check current packages installed
1
pip freeze
If you want to know where located the packages
1
pip show numpy
1-2. folder hierarchy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
opencv-project/
│
├─ src/
│ ├─ main.py
│ └─ image-processing.py
│
├─ data/
│ └─ image.png
│
├─ outputs/
│
├─ requirements.txt
├─ README.md
└─ venv-opencv/ # virtual environments
main.py
1
2
3
4
import cv2 as cv
if __name__ == "__main__":
print(cv.__version__)
I will focus on the logical structure and how to use opencv with python.
Let’s start!
This post is licensed under CC BY 4.0 by the author.