170 lines
4.9 KiB
Python
170 lines
4.9 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
测试pandas DLL模块加载
|
||
专门检查可能导致PyInstaller问题的模块
|
||
"""
|
||
|
||
import sys
|
||
import traceback
|
||
from pathlib import Path
|
||
|
||
def test_pandas_core():
|
||
"""测试pandas核心模块"""
|
||
print("=" * 50)
|
||
print("测试pandas核心模块")
|
||
print("=" * 50)
|
||
|
||
modules_to_test = [
|
||
'pandas',
|
||
'pandas._libs',
|
||
'pandas._libs.lib',
|
||
'pandas._libs.hashtable',
|
||
'pandas._libs.algos',
|
||
'pandas._libs.index',
|
||
'pandas._libs.writers',
|
||
'pandas._libs.parsers',
|
||
'pandas._libs.tslibs',
|
||
'pandas._libs.tslibs.base',
|
||
'pandas._libs.window',
|
||
'pandas._libs.window.aggregations', # 关键模块!
|
||
'pandas._libs.window.indexers',
|
||
]
|
||
|
||
success_count = 0
|
||
for module in modules_to_test:
|
||
try:
|
||
__import__(module)
|
||
print(f"✅ {module}")
|
||
success_count += 1
|
||
except ImportError as e:
|
||
print(f"❌ {module}: {e}")
|
||
except Exception as e:
|
||
print(f"⚠️ {module}: {e}")
|
||
|
||
print(f"\n成功加载: {success_count}/{len(modules_to_test)} 个模块")
|
||
return success_count == len(modules_to_test)
|
||
|
||
def test_pandas_functionality():
|
||
"""测试pandas基本功能"""
|
||
print("\n" + "=" * 50)
|
||
print("测试pandas基本功能")
|
||
print("=" * 50)
|
||
|
||
try:
|
||
import pandas as pd
|
||
import numpy as np
|
||
|
||
# 创建测试数据
|
||
df = pd.DataFrame({
|
||
'A': [1, 2, 3, 4, 5],
|
||
'B': [10, 20, 30, 40, 50]
|
||
})
|
||
|
||
print("✅ DataFrame创建成功")
|
||
|
||
# 测试窗口函数(这是出错的关键)
|
||
result = df['A'].rolling(window=2).sum()
|
||
print("✅ rolling窗口函数正常")
|
||
|
||
# 测试聚合函数
|
||
agg_result = df.groupby('A').agg({'B': 'sum'})
|
||
print("✅ groupby聚合函数正常")
|
||
|
||
# 测试Excel读写
|
||
test_file = Path('test_pandas.xlsx')
|
||
df.to_excel(test_file, index=False)
|
||
df_read = pd.read_excel(test_file)
|
||
test_file.unlink() # 删除测试文件
|
||
print("✅ Excel读写功能正常")
|
||
|
||
return True
|
||
|
||
except Exception as e:
|
||
print(f"❌ pandas功能测试失败: {e}")
|
||
traceback.print_exc()
|
||
return False
|
||
|
||
def check_pandas_installation():
|
||
"""检查pandas安装信息"""
|
||
print("\n" + "=" * 50)
|
||
print("pandas安装信息")
|
||
print("=" * 50)
|
||
|
||
try:
|
||
import pandas as pd
|
||
print(f"✅ pandas版本: {pd.__version__}")
|
||
print(f"✅ pandas路径: {pd.__file__}")
|
||
|
||
# 检查_libs目录
|
||
pandas_path = Path(pd.__file__).parent
|
||
libs_path = pandas_path / '_libs'
|
||
|
||
if libs_path.exists():
|
||
print(f"✅ _libs目录存在: {libs_path}")
|
||
|
||
# 统计.pyd文件
|
||
pyd_files = list(libs_path.glob('**/*.pyd'))
|
||
print(f"✅ 找到 {len(pyd_files)} 个.pyd文件")
|
||
|
||
# 检查关键文件
|
||
key_files = [
|
||
'window/aggregations.cp310-win_amd64.pyd',
|
||
'window/indexers.cp310-win_amd64.pyd',
|
||
'hashtable.cp310-win_amd64.pyd',
|
||
'lib.cp310-win_amd64.pyd'
|
||
]
|
||
|
||
for key_file in key_files:
|
||
file_path = libs_path / key_file
|
||
if file_path.exists():
|
||
print(f"✅ 关键文件存在: {key_file}")
|
||
else:
|
||
print(f"❌ 关键文件缺失: {key_file}")
|
||
else:
|
||
print(f"❌ _libs目录不存在: {libs_path}")
|
||
return False
|
||
|
||
return True
|
||
|
||
except Exception as e:
|
||
print(f"❌ 检查pandas安装失败: {e}")
|
||
return False
|
||
|
||
def main():
|
||
"""主函数"""
|
||
print("🔍 pandas DLL模块测试工具")
|
||
print("用于诊断PyInstaller构建问题")
|
||
print()
|
||
|
||
# 基本信息
|
||
print(f"Python版本: {sys.version}")
|
||
print(f"平台: {sys.platform}")
|
||
|
||
# 运行测试
|
||
install_ok = check_pandas_installation()
|
||
core_ok = test_pandas_core()
|
||
func_ok = test_pandas_functionality()
|
||
|
||
print("\n" + "=" * 50)
|
||
print("测试结果总结")
|
||
print("=" * 50)
|
||
|
||
if install_ok and core_ok and func_ok:
|
||
print("✅ 所有测试通过!pandas安装正常")
|
||
print("💡 如果PyInstaller仍有问题,请使用 fix_dll_build.py")
|
||
else:
|
||
print("❌ 存在问题,建议:")
|
||
if not install_ok:
|
||
print(" 1. 重新安装pandas: pip uninstall pandas && pip install pandas")
|
||
if not core_ok:
|
||
print(" 2. 检查pandas C扩展是否正确编译")
|
||
if not func_ok:
|
||
print(" 3. 检查依赖库(numpy等)是否正常")
|
||
|
||
print("=" * 50)
|
||
input("\n按Enter键退出...")
|
||
|
||
if __name__ == '__main__':
|
||
main()
|