我在 Windows Server 2012R2 上,尝试在 virtualenv 中使用 py2exe 编译脚本,每当应用程序脚本之一尝试“导入 distutils”(在我的情况下,它位于第 3 方库中的某个位置)时,我就会遇到问题,但我在这里减少了问题)。
重现步骤:
创建一个虚拟环境
virtualenv venv
call venv\Scripts\activate
Run Code Online (Sandbox Code Playgroud)在 virtualenv 中安装 py2exe
easy_install --always-unzip py2exe-0.6.9.win64-py2.7.amd64.exe
Run Code Online (Sandbox Code Playgroud)创建setup.py
from distutils.core import setup
try:
import py2exe
except:
pass
setup(
console=[
'py2exe_distutils.py'
]
)
Run Code Online (Sandbox Code Playgroud)创建 py2exe_distutils.py
import distutils
Run Code Online (Sandbox Code Playgroud)运行 py2exe
python setup.py py2exe
Run Code Online (Sandbox Code Playgroud)尝试运行生成的可执行文件
dist\py2exe_distutils.exe
Run Code Online (Sandbox Code Playgroud)它返回:
C:\Users\root\p\dist\library.zip\distutils\__init__.py:14: UserWarning: The virtualenv distutils package at %s appears to be in the same location as the system distutils?
Traceback (most recent call last):
File "py2exe_distutils.py", line 6, …Run Code Online (Sandbox Code Playgroud)