我在Windows Server 2012R2上,试图用py2exe编译脚本,在虚拟环境中,每当其中一个应用程序脚本试图"导入distutils"(在我的情况下,它在第三方库中的某个地方,但我在这里减少了问题)时,我都会遇到问题。
复制步骤:
-
创建虚拟环境
virtualenv venv call venvScriptsactivate
-
在virtualenv中安装py2exe
easy_install --always-unzip py2exe-0.6.9.win64-py2.7.amd64.exe
-
创建setup . py
from distutils.core import setup try: import py2exe except: pass setup( console=[ 'py2exe_distutils.py' ] )
-
创建py2exe_distutils.py
import distutils
运行py2exe python setup.py py2exe
尝试运行生成的可执行文件
distpy2exe_distutils.exe
它返回:
C:Usersrootpdistlibrary.zipdistutils__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, in <module>
import distutils
File "distutils__init__.pyc", line 25, in <module>
ImportError: cannot import name dist
当我直接运行脚本(python py2exe_distutils.py)时,它运行得很好,即使是从虚拟环境中运行。
我正在尝试做py2exe不支持的事情,或者我的设置有问题吗?
我在创建使用pandas 0.12.0的可执行文件时遇到了同样的问题。这对我来说很有效:在创建可执行文件之前,从基本python安装
复制distutils
文件夹。robocopy C:Python27Libdistutils venvLibdistutils /E /COPY:DAT
我在Windows 7专业版上使用virtualenv 12.0.4和py2exe 0.6.6。在这里可以找到一些额外的见解。这个回答让我想到了复制文件的方向。