Pyinstaller打包Python3.6.3 成exe文件及解决办法

1。安装pip install pyinstaller

2。或者执行pip install --upgrade pyinstaller

3。执行c:\helloworld>pyinstaller -F  helloworld.py

c:\helloworld>cd dist

c:\helloworld\dist>helloworld.exeFatal Python error: Py_Initialize: unable to load the file system codec

LookupError: unknown encoding: utf-8

Current thread 0x000002d4 (most recent call first):

我查了百度等国内外网站。试了各种办法也没找到解决办法。最后看到在Windows环境中使用Python3.5部署Apache2.4部署程序 这篇文章时提到了PYTHONPATH变量的设置。

我是用Anaconda3安装的Python3.6.3, 我报着试试看的想法,在系统变量中增加了PYTHONPATH变量,具体设置如下:

c:\Anaconda3

c:\Anaconda3\Lib\bin

c:\Anaconda3\Lib

c:\Anaconda3\Scripts

c:\Anaconda3\Dlls

没想到这样生成的helloworld.exe,再执行时不出错了

c:\helloworld\dist>helloworld.exe

hello,world!

后来又打包了一个小游戏的程序c:\shootemup>pyinstaller -F main.py,不过程序中所需要的资源文件,例如.png, wav等文件,我是直接拷贝到dist目录,

c:\shootmeup\dist>main.exe   (这个文件有232MB) 一个windows下脱离Python环境独立运行的小游戏就此诞生了。

你可能感兴趣的:(Pyinstaller打包Python3.6.3 成exe文件及解决办法)