environment:
- window1
- python 3.10.6
reference:
1. Create a virtual environment
This step can be skipped (because the author doesn't like to install anything in the global environment, so make a new environment).
First select a directory: D:\jackletter\test-pyenv
(This directory has not been created yet)
Enter powershell:
Execute the command:py -m venv test-pyenv
Activate the environment:.\test-pyenv\Scripts\Activate.ps1
2. Install Jupyter notebook
implementpip install notebook
After the installation is complete, you will see the following (pip list shows that there are many more packages):
3. Use Jupyter notebook
First select an empty directory, as follows:
The command line is positioned here, and then executed: jupyter notebook
At this point we can create a new test (ctrl+enter to execute the code):
4. Test matplotlib
First install: pip install matplotlib
, check the version after installation (pip list):
Then test in Jupyter notebook as follows:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [2, 4, 2, 6]
y1 = [e+1 for e in y]
y2 = [e+2 for e in y]
plt.plot(x, y, "b.") # b:蓝色,.:点
plt.plot(x, y1, "ro") # r:红色,o:圆圈
plt.plot(x, y2, "kx") # k:黑色,x:x字符(小叉)
plt.show() # 在窗口显示该图片
5. Test opencv
Or install first, pip install opencv-python
and check the version after installation (pip list):
Then, prepare an image in the Jupyter notebook directory:
Then test in Jupyter notebook as follows:
import cv2
img = cv2.imread('cat.webp')
cv2.imshow('cat',img)
cv2.waitKey(0)