Create Python virtual environment in Windows 11, and install PyQt6 failed and succeeded.

This video show steps to create Python virtual environment in Windows 11, also set in Thonny using the Python executable in the virtual environment, then install PyQt6 in the new created virtual environment.


To create Python virtual environment in Windows 11, enter the command in Command prompt, where envTry is the name of the virtual environment to be created.
python -m venv envTry
To activate the virtual environment, run "activate" under the "Scripts" folder in the new virtual environment.

To use the Python in the virtual environment:
> Run > Configure Interpreter...
> Select Local Python 3 in the interpreter option.
> Browser to select the Python executable in the virtual environment.

To install PyQt6 using pip, simple enter the command:
pip install PyQt6

If fail with error:
Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools".

Visit the link (https://visualstudio.microsoft.com/visual-cpp-build-tools/) listed in the error message, download and run the Microsoft C++ Build Tools. Make sure to check to include "Desktop development with C++" in Visual Studio Build Tools.



The following Python script get and show the absolute path to the Python interpreter, Python version, working platform, and also installed package version of PIL and PyQt6 shown in the video.

python_info.py
import os, sys, platform
from importlib.metadata import version
import PIL
import PyQt6

print("The absolute path to the Python interpreter:")
print(sys.executable)
print()

print(sys.implementation.name, ":")
print(sys.version)
print(sys.platform)
print("=============================================")
print("Running on: ", platform.platform())
print("=============================================")

print(PIL.__name__, PIL.__version__)
print(PyQt6.__package__, version(PyQt6.__package__))



To install OpenCV, enter the command in Command prompt:
pip install opencv-python



py_cv_batch_resize_RGB888.py, Python/cv2 to convert all jpg in 'images' folder to 240*240 RGB888 bmp in 'resized_images' folder. It was generated by Copilot.
"""
Python/cv2 to convert all jpg in 'images' folder to 240*240 RGB888 bmp in 'resized_images' folder.
"""
import os
import cv2

def resize_and_save_as_bmp(input_folder, output_folder, size):
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    
    for filename in os.listdir(input_folder):
        if filename.endswith('.jpg'):
            img_path = os.path.join(input_folder, filename)
            img = cv2.imread(img_path)
            resized_img = cv2.resize(img, size)
            
            # Save as RGB888 BMP
            bmp_filename = os.path.splitext(filename)[0] + '_240_RGB888.bmp'
            bmp_path = os.path.join(output_folder, bmp_filename)
            cv2.imwrite(bmp_path, resized_img)

input_folder = 'images'
output_folder = 'resized_images'
size = (240, 240)

resize_and_save_as_bmp(input_folder, output_folder, size)




It's used to prepare images for my another exercise Raspberry Pi Pico 2/MicroPython read bmp images and draw on ST7789 display pixel-by-pixel.



Next:
~ Python/PyQt6 SlideShow.
Resize jpg and convert to bmp in RGB888 and RGB565 mode, using Python.



Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator