win 下用 pyinstaller 转换python代码为可执行程序

选择 pyinstaller 而非 py2exe 的原因可参考: 关于python打包成exe的一点经验之谈 .

此时 pyinstaller 的最新版本为 2.1, 用 Google 搜到的相关文章基本为 2.0, 安装并不相同.
官网在 win 下的安装介绍为:

Installing in Windows

For Windows, PyWin32 is a prerequisite. Follow that link and carefully read the instructions; there is a different version of PyWin32 for each version of Python. With this done you can continue to install pip using the MS-DOS command line.

However it is particularly easy to use pip-Win, which sets up both pip and virtualenv and makes it simple to install packages and to switch between different Python interpreters. (For more on the uses of virtualenv, see Supporting Multiple Platforms below.)

When pip-Win is working, enter this command in its Command field and click Run:

venv -c -i  pyi-env-name

This creates a new virtual environment rooted at C:\Python\pyi-env-name and makes it the current environment. A new command shell window opens in which you can run commands within this environment. Enter the command

pip install PyInstaller

Whenever you want to use PyInstaller,

  • Start pip-Win
  • In the Command field enter venv pyi-env-name
  • Click Run

Then you have a command shell window in which commands execute in that environment.


1. 安装 python2.7 .
2. 安装 PyWin32 .
3. 下载 pip-Win_1.6.exe
运行 pip-Win 会安装 pip 和 virtualenv, 在其中碰到两个问题.
> "C:\Python27\lib\mimetypes.py" 报 "UnicodeDecodeError"
这是一个 bug, 有个 patch 修复  http://bugs.python.org/file18143/9291.patch .
即将 mimetypes.py 中 "UnicodeEncodeError" 替换为 "UnicodeError" 即可.
> 下载 virtualenv 失败
手动在  https://pypi.python.org/pypi/virtualenv#downloads 下载 virtualenv-1.11.2-py2.py3-none-any.whl 
执行 "C:\Python27\Scripts\pip.exe install virtualenv-1.11.2-py2.py3-none-any.whl" 即可.
4. 在 pip-Win 的 "Command" 输入框中输入 "venv -c -i pyis", 并执行.  以后要进入创建的 pyis 只需执行 "venv pyis" .
          
5. 新弹出的 cmd 窗口为创建的 pyis 环境, 在其中执行 "pip install PyInstaller" . 至此环境部署完成.
6. 在 pyis 环境中执行 "pyinstaller -F test.py", 将 python 源码转为一个独立的 exe 程序.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值