树莓派4 Linux系统下VS Code安装pywhatkit模块卡顿问题
Running setup.py bdist_wheel for opencv-python on Raspberry Pi 4 Hey there, I’ve dealt with this exact problem on my Raspberry Pi 4 before—compiling OpenCV from source via pip is super resource-heavy and slow on the Pi, which is why your installation is getting stuck. Let’s walk through the most effective fixes:
1. Use Pre-compiled OpenCV from Raspberry Pi’s Official Repository
The easiest way to avoid compiling from source is to install OpenCV via the system package manager first, then install pywhatkit. This skips the slow compilation step entirely:
# Update package lists sudo apt-get update # Install pre-compiled OpenCV for Python 3 sudo apt-get install python3-opencv # Now install pywhatkit (it will use the system's OpenCV instead of compiling) pip3 install pywhatkit
2. Increase Swap Space (If Memory is the Bottleneck)
Raspberry Pi 4’s default swap size is small, and compiling OpenCV needs a lot of memory. Temporarily increasing swap can prevent the process from hanging:
- Stop the swap service:
sudo dphys-swapfile stop - Edit the swap configuration file:
sudo nano /etc/dphys-swapfile - Find the line
CONF_SWAPSIZE=100and change it toCONF_SWAPSIZE=2048(2GB swap). - Save and exit (Ctrl+O, then Ctrl+X), then restart the swap service:
sudo dphys-swapfile start - Now try installing pywhatkit again. Once done, you can revert the swap size to avoid wearing out your SD card.
3. Specify a Compatible Older Version of opencv-python
Newer versions of opencv-python can be trickier to compile on the Pi. Try installing a slightly older version that’s more Pi-friendly:
pip3 install pywhatkit opencv-python==4.2.0.32
4. Use a Domestic PyPI Mirror for Faster Downloads
Sometimes the process appears stuck because it’s downloading source files slowly. Use a mirror to speed things up:
pip3 install pywhatkit -i https://pypi.tuna.tsinghua.edu.cn/simple
Why This Happens
When you install pywhatkit, it pulls in opencv-python as a dependency. If there’s no pre-compiled wheel available for your Raspberry Pi’s architecture, pip will try to compile OpenCV from scratch. Compiling OpenCV is a lengthy process that eats up CPU and memory—on a Pi 4, this can take hours (or appear to hang entirely). Using pre-compiled packages skips this painstaking step.
内容的提问来源于stack exchange,提问作者Kuldip Gami

