how to make vpython .exe using pyinstaller

五迷三道 提交于 2019-12-10 22:56:06

问题


I have a simple script using vpython (just testing) and I want to create a .exe file with pyinstaller.

This is the script:

from visual import*
box()

Then I run in the console:

pyinstaller sss.py

But the .exe dont work(obviously)

I've been googling about how to make the .spec file for vpython but dont find nothing.

Also tried making this .spec file

# -*- mode: python -*-

block_cipher = None


a = Analysis(['sss.py'],
             pathex=['C:\\Users\\hdfh\\Documents\\Python Scripts'],
             binaries=None,
             datas=None,
             hiddenimports=(['visual','vis','visual_common','viddle']),
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='sss.exe',
          debug=False,
          strip=None,
          upx=True,
          console=False )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=None,
               upx=True,
               name='sss')

But it dindt work


回答1:


I will reponse myself, maybe it helps someone.

When pyinstaller is used with vpython and you try to run the .exe file, it has problem for find the TGA archives placed in

C:\Anaconda2\Lib\site-packages\visual_common

So we have to edit the archive materials.py

C:\Anaconda2\Lib\site-packages\visual_common\materials.py

Here we look for the code

import sys
if hasattr(sys,'frozen') and (sys.frozen=="windows_exe" or sys.frozen=="console_exe"):
    texturePath="visual\\"
else:
    texturePath = os.path.split( __file__ )[0] + "/"
del sys

For me worked change texturePath=...to another directory, for example C:

import sys
if hasattr(sys,'frozen') and (sys.frozen=="windows_exe" or sys.frozen=="console_exe"):
    texturePath=os.path.abspath("C:/")
else:
    texturePath = os.path.abspath("C:/")
del sys

Save it and MOVE the TGA archives from visual_common to C:/ (or to the chosen place) and finally try to build the .exe from the console

pyinstaller test.py

For this works...



来源:https://stackoverflow.com/questions/39818847/how-to-make-vpython-exe-using-pyinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!