pyinstaller打包exe,使用wexpect的问题
参考github首先打包wexpect
1.进入wexpect目录执行
pyinstaller __main__.py -n wexpect
会生成dist文件夹
2.python代码A.py中使用wexpect,注意wexpect.spawn前后必须按照下面添加代码
import sys,os,wexpect
#spawn前
real_executable = sys.executable
try:if sys._MEIPASS is not None:sys.executable = os.path.join(sys._MEIPASS, "wexpect", "wexpect.exe")
except AttributeError:pass
child = wexpect.spawn('ssh root@192.168.47.128')
sys.executable = real_executable
#spawn后
try:child.expect('password',timeout=1)child.sendline("root@123")child.expect('#',timeout=1)child.sendline("touch wexpect")child.sendline("exit")
except Exception as e:print("timeout")
print('1.before = ',child.before)
print('2.after = ',child.after)
child.wait()
3.打包成onefile
pyinstaller --onefile --add-data “wexpect路径\dist;.” A.py