python - linux上用pyinstaller打包的python程序可以在windows上运行吗?
问题描述
我的 python 打包文件在 Ubuntu Linux 上完美运行。我打开终端并输入
./[filename]
并且程序运行,但在 Windows 终端cmd
和powershell
. 我还尝试重命名文件以.exe
使其可执行,但它也对我不起作用。
python
另外,我没有pyinstaller
安装在 Windows 机器上。
解决方案
不,linux 打包的 pyinstaller 程序不会在 windows 上运行,您必须获取脚本源并使用 pyinstaller 在 windows 上重新打包。因为 pysintaller 里面封装了可执行的二进制程序和共享库,在 Windows 和 Linux 中的格式不同。
pyinstaller 打包文件的内容是一种特殊的自定义 pysintaller 格式的 SFX 存档。我刚刚查看了 pyinstaller 的模块代码,并根据收到的知识实现了下一个简单的脚本来提取 pyinstaller 打包文件的所有内容,fname
在脚本中提供:
import os, shutil
from PyInstaller.archive.readers import CArchiveReader
fname = 'z13.exe' # Provide packed filename here
ddir = fname + '_extracted/'
assert os.path.exists(fname), fname + ' not exists!'
if os.path.exists(ddir):
shutil.rmtree(ddir)
os.makedirs(ddir, exist_ok = True)
r = CArchiveReader(fname)
for fname in r.contents():
os.makedirs(ddir + os.path.dirname(fname), exist_ok = True)
data = r.extract(fname)[1]
with open(ddir + fname, 'wb') as f:
f.write(data)
推荐阅读
- nopcommerce-4.0 - 找不到默认重量和尺寸 - NopCommerce
- javascript - 关系查询请求的问题
- android - 使用 android studio 与 ./gradlew assemble[FlavourName]Release 生成风味签名的 APK 会提供不同的结果
- r - 匹配所有数字时的r for循环
- ruby-on-rails - 设置 Heroku rails GOOGLE_APPLICATION_CREDENTIALS (firebase) 错误
- python - ConnectionResetError:[Errno 104] 通过 Selenium 进行移动测试,在 Heroku 上由对等方和 ERR_NAME_NOT_RESOLVED 重置连接
- python - 在异步环境中使用 PRAW 从 reddit 中选择随机帖子的更快方法
- java - insertInto 输出返回“?” 而不是真正的价值
- javascript - OnFocus 事件不会在 Safari 中触发
- go - 将 go/types 转换为 reflect.Type?