92 lines
2.6 KiB
Python
92 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
PyQt6快速安装脚本 - 使用清华镜像源
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
|
|
def install_with_mirror(package, mirror=None):
|
|
"""使用镜像源安装包"""
|
|
try:
|
|
print(f"正在安装 {package}...")
|
|
|
|
if mirror:
|
|
cmd = [sys.executable, "-m", "pip", "install", package, "-i", mirror]
|
|
print(f"使用镜像源: {mirror}")
|
|
else:
|
|
cmd = [sys.executable, "-m", "pip", "install", package]
|
|
|
|
result = subprocess.run(
|
|
cmd,
|
|
capture_output=False, # 显示安装进度
|
|
text=True
|
|
)
|
|
|
|
if result.returncode == 0:
|
|
print(f"✓ {package} 安装成功")
|
|
return True
|
|
else:
|
|
print(f"✗ {package} 安装失败")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"✗ 安装 {package} 时出错: {e}")
|
|
return False
|
|
|
|
def main():
|
|
print("=== PyQt6 快速安装器 ===\n")
|
|
|
|
# 国内镜像源列表
|
|
mirrors = [
|
|
"https://pypi.tuna.tsinghua.edu.cn/simple/",
|
|
"https://mirrors.aliyun.com/pypi/simple/",
|
|
"https://pypi.douban.com/simple/",
|
|
]
|
|
|
|
packages = [
|
|
"PyQt6>=6.4.0",
|
|
"numpy>=1.21.0"
|
|
]
|
|
|
|
success_count = 0
|
|
failed_packages = []
|
|
|
|
for package in packages:
|
|
installed = False
|
|
|
|
for mirror in mirrors:
|
|
print(f"\n尝试使用镜像源安装 {package}:")
|
|
if install_with_mirror(package, mirror):
|
|
installed = True
|
|
success_count += 1
|
|
break
|
|
else:
|
|
print(f"镜像源 {mirror} 失败,尝试下一个...")
|
|
|
|
if not installed:
|
|
print(f"所有镜像源都失败,尝试官方源安装 {package}...")
|
|
if install_with_mirror(package):
|
|
installed = True
|
|
success_count += 1
|
|
|
|
if not installed:
|
|
failed_packages.append(package)
|
|
|
|
print(f"\n=== 安装结果: {success_count}/{len(packages)} 成功 ===")
|
|
|
|
if success_count == len(packages):
|
|
print("\n✅ 所有包安装成功!")
|
|
print("\n现在可以运行测试:")
|
|
print("python3 test_pyqt6.py")
|
|
print("\n启动GUI界面:")
|
|
print("python3 monitor_gui.py")
|
|
return True
|
|
else:
|
|
print(f"\n❌ 以下包安装失败: {', '.join(failed_packages)}")
|
|
print("请检查网络连接或尝试手动安装")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1) |