python pip 安装包失败,dllwrap 错误: "无法找到 vcvarsall.bat

4 投票
3 回答
8161 浏览
提问于 2025-04-16 14:27

我在档案里找不到这个问题。是不是mingw/msys有点问题?
[我需要修复vcvarsall.bat,这样我才能安装其他包。]

我在用pip.exe安装python包'twisted'时失败了。

我已经安装了python2.6和mingw/msys。
我的环境变量%PATH%里包含了C:\MinGW\C:\MinGW\mingw32\bin

首先:用pip.exe install twisted命令时失败,提示错误:找不到vcvarsall.bat
我创建了一个文件G:\Programs (x86)\Python 2.6\Lib\distutils\distutils.cfg,里面包含:

[build]
compiler=mingw32

现在我收到的错误是:

g:\Programs (x86)\Python 2.6>python Scripts\pip-script.py install twisted
Downloading/unpacking twisted
  Running setup.py egg_info for package twisted
Downloading/unpacking zope.interface (from twisted)
  Running setup.py egg_info for package zope.interface
Requirement already satisfied (use --upgrade to upgrade): setuptools in g:\progr
ams (x86)\python 2.6\lib\site-packages (from zope.interface->twisted)
Installing collected packages: twisted, zope.interface
  Running setup.py install for twisted
    C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ig:\Programs (x86)\Python
2.6\include" "-Ig:\Programs (x86)\Python 2.6\PC" -c conftest.c -o conftest.o
    conftest.c:1:21: fatal error: rpc/rpc.h: No such file or directory
    compilation terminated.
    C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ig:\Programs (x86)\Python
2.6\include" "-Ig:\Programs (x86)\Python 2.6\PC" -c conftest.c -o conftest.o
    conftest.c:1:23: fatal error: sys/epoll.h: No such file or directory
    compilation terminated.
    building 'twisted.protocols._c_urlarg' extension
    C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -DWIN32=1 "-Ig:\Programs (x8
6)\Python 2.6\include" "-Ig:\Programs (x86)\Python 2.6\PC" -c twisted/protocols/
_c_urlarg.c -o build\temp.win32-2.6\Release\twisted\protocols\_c_urlarg.o
    twisted/protocols/_c_urlarg.c: In function 'unquote':
    twisted/protocols/_c_urlarg.c:41:50: warning: 'tmp' may be used uninitialize
d in this function
    C:\MinGW\bin\dllwrap.exe -mno-cygwin -mdll -static --output-lib build\temp.w
in32-2.6\Release\twisted\protocols\lib_c_urlarg.a --def build\temp.win32-2.6\Rel
ease\twisted\protocols\_c_urlarg.def -s build\temp.win32-2.6\Release\twisted\pro
tocols\_c_urlarg.o "-Lg:\Programs (x86)\Python 2.6\libs" "-Lg:\Programs (x86)\Py
thon 2.6\PCbuild" -lpython26 -lmsvcr90 -o build\lib.win32-2.6\twisted\protocols\
_c_urlarg.pyd
    _c_urlarg.exp: file not recognized: File format not recognized
    collect2: ld returned 1 exit status
    dllwrap: gcc exited with status 1
    error: command 'dllwrap' failed with exit status 1
    Complete output from command "g:\Programs (x86)\Python 2.6\python.exe" -c "i
mport setuptools;__file__='g:\\Programs (x86)\\Python 2.6\\build\\twisted\\setup
.py';execfile(__file__)" install --single-version-externally-managed --record c:
\users\jake\appdata\local\temp\pip-3y_c1e-record\install-record.txt:
    running install

running build

running build_py

running egg_info

writing requirements to Twisted.egg-info\requires.txt

writing Twisted.egg-info\PKG-INFO

writing top-level names to Twisted.egg-info\top_level.txt

writing dependency_links to Twisted.egg-info\dependency_links.txt

reading manifest file 'Twisted.egg-info\SOURCES.txt'

writing manifest file 'Twisted.egg-info\SOURCES.txt'

running build_ext

C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ig:\Programs (x86)\Python 2.6\
include" "-Ig:\Programs (x86)\Python 2.6\PC" -c conftest.c -o conftest.o

conftest.c:1:21: fatal error: rpc/rpc.h: No such file or directory

compilation terminated.

C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall "-Ig:\Programs (x86)\Python 2.6\
include" "-Ig:\Programs (x86)\Python 2.6\PC" -c conftest.c -o conftest.o

conftest.c:1:23: fatal error: sys/epoll.h: No such file or directory

compilation terminated.

building 'twisted.protocols._c_urlarg' extension

C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -DWIN32=1 "-Ig:\Programs (x86)\P
ython 2.6\include" "-Ig:\Programs (x86)\Python 2.6\PC" -c twisted/protocols/_c_u
rlarg.c -o build\temp.win32-2.6\Release\twisted\protocols\_c_urlarg.o

twisted/protocols/_c_urlarg.c: In function 'unquote':

twisted/protocols/_c_urlarg.c:41:50: warning: 'tmp' may be used uninitialized in
 this function

writing build\temp.win32-2.6\Release\twisted\protocols\_c_urlarg.def

C:\MinGW\bin\dllwrap.exe -mno-cygwin -mdll -static --output-lib build\temp.win32
-2.6\Release\twisted\protocols\lib_c_urlarg.a --def build\temp.win32-2.6\Release
\twisted\protocols\_c_urlarg.def -s build\temp.win32-2.6\Release\twisted\protoco
ls\_c_urlarg.o "-Lg:\Programs (x86)\Python 2.6\libs" "-Lg:\Programs (x86)\Python
 2.6\PCbuild" -lpython26 -lmsvcr90 -o build\lib.win32-2.6\twisted\protocols\_c_u
rlarg.pyd

_c_urlarg.exp: file not recognized: File format not recognized

collect2: ld returned 1 exit status

dllwrap: gcc exited with status 1

warning: manifest_maker: standard file '-c' not found

error: command 'dllwrap' failed with exit status 1

----------------------------------------
Command "g:\Programs (x86)\Python 2.6\python.exe" -c "import setuptools;__file__
='g:\\Programs (x86)\\Python 2.6\\build\\twisted\\setup.py';execfile(__file__)"
install --single-version-externally-managed --record c:\users\jake\appdata\local
\temp\pip-3y_c1e-record\install-record.txt failed with error code 1
Storing complete log in C:\Users\jake\AppData\Roaming\pip\pip.log

3 个回答

0

在Windows系统上,我安装了Visual Studio 2008(vcsetup.exe)来解决这个问题。

更新链接: http://www.microsoft.com/en-us/download/details.aspx?id=15336

如果你使用的是Python 3.3,可以用Visual Studio 2010。

3

问题是:为什么在pip中使用dllwrap会出现这个错误?

_foo.exp: file not recognized: File format not recognized

简单的回答是:检查你的PATH设置。MinGW\bin需要放在前面。

详细的回答是:一段时间我在用一个变通的方法。我从pip.log中拿到了dllwrap命令,然后直接执行它。这样就能生成.pyd文件,让pip安装顺利完成。

我在调用dllwrap的这两种方式中都加了--verbose参数。在pip中是这样做的。

dlltool: Opened temporary file: dumlc.s
dlltool: run: as   -o _bcrypt.exp dumlc.s
dlltool: Generated exports file

从命令行调用dllwrap时得到了这个结果。

C:\MinGW\bin\dlltool: Opened temporary file: demmc.s
C:\MinGW\bin\dlltool: run: C:\MinGW\bin\as   -o _bcrypt.exp demmc.s
C:\MinGW\bin\dlltool: Generated exports file

我的电脑是64位的Windows 7,但装的是32位的Python 2.7。虽然是新电脑,但似乎预装了AMD APP SDK。这个SDK里有一个as.exe,默认输出是64位的。

我的解决办法是修改PATH,把C:\MinGW\bin放在C:\Program Files (x86)\AMD APP\bin\x86_64之前。

这个问题可以在Python代码中更稳妥地解决,不过我还没找到应该在virtualenv、pip还是distutils中进行修改。

使用MinGW构建扩展时还需要另外两件事,我在这里简单重复一下。

配置distutils使用MinGW编译器

这可以通过多种文件或命令行参数来完成。我选择在我的主目录下创建一个文件。

$ cat ~/pydistutils.cfg
[build]
compiler = mingw32

修改distutils以去掉-mno-cygwin选项

作为管理员编辑Lib/distutils/cygwinccompiler.py文件。删除四个-mno-cygwin选项。

s/ -mno-cygwin//

-mno-cygwin在gcc中已经被弃用了,现在会报错。

详情见 http://bugs.python.org/issue12641

3

这可能是Python的一个bug。你可以查看这个链接了解更多信息:http://bugs.python.org/issue2698

同时,你可以安装ActivePython,然后通过PyPM来安装Twisted(这样不需要编译器)。

另外,你也可以使用官方的安装包……不过我推荐前面提到的办法,因为这样你将来可以很方便地“升级”到Twisted的新版本。

撰写回答