问题描述
所以我刚用pygame制作了我的第一个游戏。我想也应该注意我在Mac上使用ios的情况
我下载了pyinstaller,当我使用pyinstaller时,我得到一个文件,当我尝试执行该文件时,它会收到图1中的以下消息。 文件的编码对于Python 3.x无效。 IDLE会将其转换为UTF-8。当前的编码是什么
我不知道要用什么代替UTF-8(这意味着什么),所以我只按ok,就会在图片2中得到以下消息。
因此,当我要将.py文件转换为可执行文件时,它只是将其转换为需要解码的.pyc文件。 (无论什么意思)
我用pycharm编写了代码,当我将其放入pyinstaller时,它看起来如图3所示:
无论如何都感谢您的帮助!
我已经尝试过pyinstaller --onefile -w [文件名],但是picture 4都不起作用
下面是我执行pyinstaller之后的代码,这可能对我有所帮助。
$ pyinstaller /Users/colemanschnaak/PycharmProjects/flappybird/flappybird.py
282 INFO: PyInstaller: 4.0
282 INFO: Python: 3.7.7
299 INFO: Platform: Darwin-17.7.0-x86_64-i386-64bit
301 INFO: wrote /Users/colemanschnaak/flappybird.spec
305 INFO: UPX is not available.
306 INFO: Extending PYTHONPATH with paths
['/Users/colemanschnaak/PycharmProjects/flappybird','/Users/colemanschnaak']
352 INFO: checking Analysis
359 INFO: Building because inputs changed
359 INFO: Initializing module dependency graph...
362 INFO: Caching module graph hooks...
381 INFO: Analyzing base_library.zip ...
2778 INFO: Processing pre-find module path hook distutils from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
2782 INFO: distutils: retargeting to non-venv dir '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7'
4452 INFO: Caching module dependency graph...
4564 INFO: running Analysis Analysis-00.toc
4582 INFO: Analyzing /Users/colemanschnaak/PycharmProjects/flappybird/flappybird.py
4984 INFO: Processing module hooks...
4985 INFO: Loading module hook 'hook-pkg_resources.py' from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks'...
5203 INFO: Processing pre-safe import module hook win32com from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/_pyinstaller_hooks_contrib/hooks/pre_safe_import_module/hook-win32com.py'.
5603 WARNING: Hidden import "pkg_resources.markers" not found!
5605 INFO: Excluding import '__main__'
5606 INFO: Removing import of __main__ from module pkg_resources
5607 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks'...
5610 INFO: Loading module hook 'hook-encodings.py' from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks'...
5695 INFO: Loading module hook 'hook-pygame.py' from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks'...
5697 WARNING: Hidden import "pygame._view" not found!
5698 INFO: Loading module hook 'hook-sysconfig.py' from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks'...
5712 INFO: Loading module hook 'hook-xml.py' from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks'...
5978 INFO: Loading module hook 'hook-distutils.py' from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks'...
5997 INFO: Looking for ctypes DLLs
6011 INFO: Analyzing run-time hooks ...
6015 INFO: Including run-time hook '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pkgres.py'
6024 INFO: Looking for dynamic libraries
6762 INFO: Looking for eggs
6763 INFO: Using Python library /Library/Frameworks/Python.framework/Versions/3.7/Python
6770 INFO: Warnings written to /Users/colemanschnaak/build/flappybird/warn-flappybird.txt
6806 INFO: Graph cross-reference written to /Users/colemanschnaak/build/flappybird/xref-flappybird.html
6821 INFO: checking PYZ
6824 INFO: Building because toc changed
6824 INFO: Building PYZ (ZlibArchive) /Users/colemanschnaak/build/flappybird/PYZ-00.pyz
7273 INFO: Building PYZ (ZlibArchive) /Users/colemanschnaak/build/flappybird/PYZ-00.pyz completed successfully.
7280 INFO: checking PKG
7281 INFO: Building because toc changed
7282 INFO: Building PKG (CArchive) PKG-00.pkg
7298 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
7299 INFO: Bootloader /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/bootloader/Darwin-64bit/run
7299 INFO: checking EXE
7301 INFO: Building because toc changed
7302 INFO: Building EXE from EXE-00.toc
7302 INFO: Appending archive to EXE /Users/colemanschnaak/build/flappybird/flappybird
7308 INFO: Fixing EXE for code signing /Users/colemanschnaak/build/flappybird/flappybird
7313 INFO: Building EXE from EXE-00.toc completed successfully.
7315 INFO: checking COLLECT
7315 INFO: Building COLLECT because COLLECT-00.toc is non existent
WARNING: The output directory "/Users/colemanschnaak/dist/flappybird" and ALL ITS CONTENTS will be REMOVED! Continue? (y/N)
然后我点击“是”,我得到了:
WARNING: The output directory "/Users/colemanschnaak/dist/flappybird" and ALL ITS CONTENTS will be REMOVED! Continue? (y/N)y
On your own risk,you can use the option `--noconfirm` to get rid of this question.
312239 INFO: Removing dir /Users/colemanschnaak/dist/flappybird
312266 INFO: Building COLLECT COLLECT-00.toc
314548 INFO: Building COLLECT COLLECT-00.toc completed successfully.
如果我打不了:
WARNING: The output directory "/Users/colemanschnaak/dist/flappybird" and ALL ITS CONTENTS will be REMOVED! Continue? (y/N)n
User aborted
在我的Mac上,python的默认版本也是2.7
$ python --version
Python 2.7.18
与为什么我不能打包.py文件有什么关系?感觉我是用3.7写的
解决方法
我认为pyinstaller无法理解flappybird.py的路径。您可以尝试做一件事,将整个fliftbird目录复制到pyinstaller.exe所在的(python根)python37 \ libs \ site-packeges \ pyinstaller \中,然后使用该目录打开bash并尝试 pyinstaller -w -f“ Flapybird \ flapybird.py” 命令。
,如果您使用python 3编写代码,则可以添加一些强调的字符。但是Python 2 IDLE无法读取这些字符。
PS:我编写了here一个GUI,该GUI将.py
或.pyw
文件转换为.exe
文件。