gwa*_*n13 6 python pyinstaller pandas
我试图将一个简短的python脚本捆绑到一个可执行文件中.我能够成功运行pyinstaller
pyinstaller script.py
Run Code Online (Sandbox Code Playgroud)
但是,当我运行可执行文件时,我收到以下错误.我已经尝试了一切,似乎没有任何工作.
C:\Users\...\Python\dist\script>script
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "c:\users\user\appdata\local\temp\pip-build-0pjuke\pyinstaller\PyInst
aller\loader\pyimod03_importers.py", line 363, in load_module
File "c:\python27\lib\site-packages\pandas\__init__.py", line 13, in <module>
"extensions first.".format(module))
ImportError: C extension: lib not built. If you want to import pandas from the s
ource directory, you may need to run 'python setup.py build_ext --inplace' to bu
ild the C extensions first.
script returned -1
Run Code Online (Sandbox Code Playgroud)
以下是我脚本中的导入:
import pandas
from simple_salesforce import Salesforce
from pandas import Series, DataFrame
import vertica_python
from StringIO import StringIO
Run Code Online (Sandbox Code Playgroud)
Zer*_*ero 12
编辑您的.spec文件以添加下面显示的行a = Analysis part.然后使用--onefile flag- 例如,pyinstaller --onefile my_project.spec
a = Analysis(...)
# Add the following
def get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_path
dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)
Run Code Online (Sandbox Code Playgroud)
这是必要的原因是PyInstaller正在抓取pandas python代码,但没有抓住lib.这意味着当pandas代码运行时(从可执行文件的"内部")它找不到lib - 所以它试图提供帮助并建议你需要构建它.
解决方法详见http://github.com/pyinstaller/pyinstaller/issues/1580 - 它似乎不适用于所有版本/操作系统,所以祝你好运.
Dan*_*bib -2
错误
ImportError: C extension: lib not built.
Run Code Online (Sandbox Code Playgroud)
明确告诉你要跑python setup.py build_ext --inplace。构建 C 扩展
| 归档时间: |
|
| 查看次数: |
6565 次 |
| 最近记录: |