You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

macOS Sierra 10.12.6下PyQt5报ImportError: _futimens解决求助

Fixing PyQt5 ImportError on Older macOS Versions

Hey there! I totally get how frustrating this error can be when you're just starting out with PyQt5. Let's break down what's happening and walk through the solutions step by step.

What's Causing the Error?

The ImportError about the missing _futimens symbol happens because the PyQt5 version you installed via pip3 is compiled for macOS 10.13 or newer, but your operating system is older than that. The _futimens function is part of the system library (libSystem.B.dylib) that only exists in macOS 10.13+, so your system can't find it when trying to load PyQt5's libraries.

Step-by-Step Solutions

1. Install a Compatible Older Version of PyQt5

Newer PyQt5 versions dropped support for older macOS releases. The last PyQt5 version that supports macOS 10.11 and above is 5.12.3. To install it, run this command in your terminal:

pip3 install pyqt5==5.12.3

Once the installation finishes, try running your PyQt5 code again—this should resolve the missing symbol error.

2. Compile PyQt5 from Source (If Pip Installation Fails)

If the above pip command doesn't work (maybe due to missing wheels), you can compile PyQt5 from source using an older Qt version that supports your macOS:

  • First, install Qt 5.12 via Homebrew (this version supports older macOS):
    brew install qt@5.12
    
  • Then, install PyQt5 from source, pointing it to the Qt 5.12 installation:
    pip3 install pyqt5 --no-binary :all: --global-option=--qmake=/usr/local/opt/qt@5.12/bin/qmake
    

Note: Compiling from source might take a while, but it's a reliable way to get a version tailored to your system.

3. Quick Check After Installation

After installing the compatible version, run your original code again:

from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication
import sys
class Example(QMainWindow):
    def __init__(self):
        super().__init__()
        btn = QPushButton("Hello World!", self)
        btn.move(50,75)
        self.setGeometry(100, 100, 200,150)
        self.setWindowTitle('PyQt Window')
        self.show()
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

You should see your "Hello World!" button window pop up without errors!

Quick Tips for New Developers

  • When installing packages that have system dependencies (like PyQt5), always check the package's release notes to see which operating system versions it supports.
  • If you run into version compatibility issues, searching for the last package version that supports your OS is usually the fastest fix.

内容的提问来源于stack exchange,提问作者DedUV

火山引擎 最新活动