这可能不是最好的方法(我无法弄清楚 py2exe),但您可以创建一个通过二进制安装程序包运行的批处理文件,用于安装 python、pip 和其他,然后运行pip install -r requirements.txt
如果使用 pip,此方法需要互联网连接。
您也可以压缩 python 目录。安装python,解压文件夹,复制过来?
或者包括所有的 Windows 安装程序二进制文件?
点示例:
How to pip install packages according to requirements.txt from a local directory?
pip 安装程序:http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip
python 安装程序:https://www.python.org/downloads/
示例批处理脚本:
@ ECHO off
@ REM off
# msi examples
msiexec /i dependencies\python-2.7.6.msi
msiexec /i dependencies\pycurl-7.19.0.2.win32-py2.7.msi
# exe examples
start dependencies\paramiko-1.7.7.1.win32-py2.7.exe
start dependencies\pycrypto-2.3.win32-py2.7.exe
start dependencies\pip-1.5.4.win32-py2.7.exe
start dependencies\wxPython3.0-win32-3.0.0.0-py27.exe
pip install image
pip install -r requirements.txt
pause
示例 requirements.txt:
image==1.2
BeautifulSoup==3.2.1
PyYAML==3.10
beautifulsoup4==4.3.2
distribute==0.6.49
idna==0.3
pyparsing==2.0.1
python-dateutil==2.2
pywin==0.3.1
selenium==2.40.0
six==1.6.1
一个有用的 pip 函数是使用 pip freeze (docs) 来获取依赖项/要求。
批量设置python路径示例:
set path=%path%;C:\python27;C:\python27\scripts
reg ADD "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d %path% /f