python 使用pyinstaller生成exe,以及编译报错:编译时报错如下:No module named timedeltas not build. If you want import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to
因为电脑以前安装过pip
所以直接cmd 管理员权限运行:pip install pyinstaller
安装successfully之后就可以转换.py程序了.
cmd管理员权限打开,cd到你要转换的文件目录下。
比如,文件在D:\TEST下,CMD默认打开C:\。执行:
D:
cd TEST
pyinstaller yourprogram.py
教程:
https://pyinstaller.readthedocs.io/en/v3.3.1/usage.html
https://wizardforcel.gitbooks.io/py-sec-tutorial/content/zh-cn/0x4.html
举例:
pyinstaller.py --console --onefile sync.py
成功后如下:
在dist文件夹下的sync.exe就是我们最后需要的文件。
Issue:
程序中可能引用了pandas包,编译时报错如下:No module named timedeltas not build. If you want import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extension.
我们到文件目录下,看到之前pyinstaller为我们生成了sync.spec文件。
打开之前生成的【文件名.spec】文件:在hiddenimports=[] 中添加对应的pandas命令。如下黄色部分。
再运行:
pyinstaller sync.spec
1 # -*- mode: python -*- 2 3 block_cipher = None 4 5 6 a = Analysis(['sync.py'], 7 pathex=['D:\\Pyinstaller\\5'], 8 binaries=[], 9 datas=[], 10 hiddenimports=['pandas', 'pandas._libs.tslibs.timedeltas'], 11 hookspath=[], 12 runtime_hooks=[], 13 excludes=[], 14 win_no_prefer_redirects=False, 15 win_private_assemblies=False, 16 cipher=block_cipher) 17 pyz = PYZ(a.pure, a.zipped_data, 18 cipher=block_cipher) 19 exe = EXE(pyz, 20 a.scripts, 21 a.binaries, 22 a.zipfiles, 23 a.datas, 24 name='sync', 25 debug=False, 26 strip=False, 27 upx=True, 28 runtime_tmpdir=None, 29 console=True )
在dist文件夹下的sync.exe就是我们最后需要的文件。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~