102 lines
2.4 KiB
Python
102 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
测试构建脚本 - 验证依赖和配置
|
|
"""
|
|
|
|
import sys
|
|
import subprocess
|
|
import platform
|
|
|
|
def test_dependencies():
|
|
"""测试关键依赖"""
|
|
print("=" * 50)
|
|
print("测试关键依赖")
|
|
print("=" * 50)
|
|
|
|
dependencies = [
|
|
'pandas',
|
|
'numpy',
|
|
'openpyxl',
|
|
'pyinstaller'
|
|
]
|
|
|
|
for dep in dependencies:
|
|
try:
|
|
__import__(dep)
|
|
print(f"✅ {dep} - 已安装")
|
|
except ImportError:
|
|
print(f"❌ {dep} - 未安装")
|
|
return False
|
|
|
|
return True
|
|
|
|
def test_hidden_imports():
|
|
"""测试隐藏导入"""
|
|
print("\n" + "=" * 50)
|
|
print("测试隐藏导入")
|
|
print("=" * 50)
|
|
|
|
hidden_imports = [
|
|
'numpy.core._methods',
|
|
'pandas._libs.window.aggregations',
|
|
'ctypes.util'
|
|
]
|
|
|
|
for imp in hidden_imports:
|
|
try:
|
|
parts = imp.split('.')
|
|
module = __import__(parts[0])
|
|
for part in parts[1:]:
|
|
module = getattr(module, part)
|
|
print(f"✅ {imp} - 可访问")
|
|
except (ImportError, AttributeError) as e:
|
|
print(f"⚠️ {imp} - 无法访问: {e}")
|
|
|
|
return True
|
|
|
|
def test_pyinstaller():
|
|
"""测试PyInstaller"""
|
|
print("\n" + "=" * 50)
|
|
print("测试PyInstaller")
|
|
print("=" * 50)
|
|
|
|
try:
|
|
result = subprocess.run([
|
|
sys.executable, '-m', 'PyInstaller', '--version'
|
|
], capture_output=True, text=True)
|
|
|
|
if result.returncode == 0:
|
|
version = result.stdout.strip()
|
|
print(f"✅ PyInstaller版本: {version}")
|
|
return True
|
|
else:
|
|
print(f"❌ PyInstaller测试失败: {result.stderr}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ PyInstaller测试出错: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print(f"Python版本: {sys.version}")
|
|
print(f"操作系统: {platform.system()} {platform.release()}")
|
|
print(f"架构: {platform.machine()}")
|
|
|
|
success = True
|
|
success &= test_dependencies()
|
|
success &= test_hidden_imports()
|
|
success &= test_pyinstaller()
|
|
|
|
print("\n" + "=" * 50)
|
|
if success:
|
|
print("✅ 所有测试通过,可以进行构建")
|
|
else:
|
|
print("❌ 存在问题,请先解决依赖问题")
|
|
print("=" * 50)
|
|
|
|
return success
|
|
|
|
if __name__ == '__main__':
|
|
main()
|