我在python中有一个非常简单的程序,它在Spyder或Eclipse中运行得很好,但在用py2exe打包后在命令行执行时失败了。
操作系统是法语Windows 7,我正在使用:
来自Anaconda 2.1.0(64位)的Python 3.4.1
熊猫0.15.2 np19py34_0
cython 0.21.2
我得到的错误如下:
Parent module '' not loaded, cannot perform relative import
Traceback (most recent call last):
File "Main.py", line 2, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Anaconda3\lib\site-packages\zipextimporter.py", line 86, in load_module
return zipimport.zipimporter.load_module(self, fullname)
File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Anaconda3\lib\site-packages\zipextimporter.py", line 109, in load_module self.get_data)
File "pandas\hashtable.pyx", line 9, in init pandas.hashtable (pandas\hashtable.c:23000)
SystemError: Parent module '' not loaded, cannot perform relative import
这是main.py编码:
# -*- coding: utf-8 -*-
import pandas
data = pandas.read_hdf ("C:/temp/test.h5", "MainData")
file = open ("C:/temp/log.txt", "a+")
strMessage = ""
for arg in data.columns:
strMessage += str (arg) + "\n"
file.write (strMessage)
file.close()
和setup.py:
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
excludes = ['tkinter']
opts = {'py2exe': {'excludes':excludes,
'bundle_files': 1,
'compressed': True,
'optimize':2}}
setup(name='Core',
version='1.0',
description = "Core Engine",
console = [{"script": "Main.py",
"dest_base": "Core"}],
options = opts)
我正在执行以下命令行来构建我的可执行文件:
python setup.py py2exe
我尝试卸载并重新安装Anaconda3,用“conda”和/或“pip”升级pandas和cython,但没有任何效果。
非常感谢任何帮助!