12

我在使用 pip 安装 python 模块时遇到问题。下面是命令窗口的输出:

请注意,我在尝试安装 GDAL 模块之前立即安装了 pip。

我在运行 python 2.7 的 w7 64 位机器上

    Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\jnunn\Desktop>python get-pip.py
Downloading/unpacking pip
Downloading pip-1.2.1.tar.gz (102Kb): 102Kb downloaded
Running setup.py egg_info for package pip

warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.txt' found under directory
'docs\_build'
no previously-included directories found matching 'docs\_build\_sources'
Installing collected packages: pip
Running setup.py install for pip

warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.txt' found under directory
'docs\_build'
no previously-included directories found matching 'docs\_build\_sources'
Installing pip-script.py script to C:\Python26\ArcGIS10.1\Scripts
Installing pip.exe script to C:\Python26\ArcGIS10.1\Scripts
Installing pip.exe.manifest script to C:\Python26\ArcGIS10.1\Scripts
Installing pip-2.7-script.py script to C:\Python26\ArcGIS10.1\Scripts
Installing pip-2.7.exe script to C:\Python26\ArcGIS10.1\Scripts
Installing pip-2.7.exe.manifest script to C:\Python26\ArcGIS10.1\Scripts
Successfully installed pip
Cleaning up...

C:\Users\jnunn\Desktop>pip install gdal
Downloading/unpacking gdal
Downloading GDAL-1.9.1.tar.gz (420kB): 420kB downloaded
Running setup.py egg_info for package gdal

Installing collected packages: gdal
Running setup.py install for gdal
building 'osgeo._gdal' extension
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo
/Ox /MD /W3 /GS- /DNDEBUG -I../../port -I../../gcore -I../../alg -I../../ogr/ -I
C:\Python26\ArcGIS10.1\include -IC:\Python26\ArcGIS10.1\PC -IC:\Python26\ArcGIS1
0.1\lib\site-packages\numpy\core\include /Tpextensions/gdal_wrap.cpp /Fobuild\te
mp.win32-2.7\Release\extensions/gdal_wrap.obj
gdal_wrap.cpp
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) :
warning C4530: C++ exception handler used, but unwind semantics are not enabled
. Specify /EHsc
extensions/gdal_wrap.cpp(2853) : fatal error C1083: Cannot open include file
: 'cpl_port.h': No such file or directory
error: command '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\c
l.exe"' failed with exit status 2
Complete output from command C:\Python26\ArcGIS10.1\python.exe -c "import se
tuptools;__file__='c:\\users\\jnunn\\appdata\\local\\temp\\pip-build\\gdal\\setu
p.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'
))" install --record c:\users\jnunn\appdata\local\temp\pip-f7tgze-record\install
-record.txt --single-version-externally-managed:
running install

running build

running build_py

creating build

creating build\lib.win32-2.7

copying gdal.py -> build\lib.win32-2.7

copying ogr.py -> build\lib.win32-2.7

copying osr.py -> build\lib.win32-2.7

copying gdalconst.py -> build\lib.win32-2.7

copying gdalnumeric.py -> build\lib.win32-2.7

creating build\lib.win32-2.7\osgeo

copying osgeo\gdal.py -> build\lib.win32-2.7\osgeo

copying osgeo\gdalconst.py -> build\lib.win32-2.7\osgeo

copying osgeo\gdalnumeric.py -> build\lib.win32-2.7\osgeo

copying osgeo\gdal_array.py -> build\lib.win32-2.7\osgeo

copying osgeo\ogr.py -> build\lib.win32-2.7\osgeo

copying osgeo\osr.py -> build\lib.win32-2.7\osgeo

copying osgeo\__init__.py -> build\lib.win32-2.7\osgeo

running build_ext

building 'osgeo._gdal' extension

creating build\temp.win32-2.7

creating build\temp.win32-2.7\Release

creating build\temp.win32-2.7\Release\extensions

c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox
/MD /W3 /GS- /DNDEBUG -I../../port -I../../gcore -I../../alg -I../../ogr/ -IC:\P
ython26\ArcGIS10.1\include -IC:\Python26\ArcGIS10.1\PC -IC:\Python26\ArcGIS10.1\
lib\site-packages\numpy\core\include /Tpextensions/gdal_wrap.cpp /Fobuild\temp.w
in32-2.7\Release\extensions/gdal_wrap.obj

gdal_wrap.cpp

c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : war
ning C4530: C++ exception handler used, but unwind semantics are not enabled. Sp
ecify /EHsc

extensions/gdal_wrap.cpp(2853) : fatal error C1083: Cannot open include file: 'c
pl_port.h': No such file or directory

error: command '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.ex
e"' failed with exit status 2

----------------------------------------
Command C:\Python26\ArcGIS10.1\python.exe -c "import setuptools;__file__='c:\\us
ers\\jnunn\\appdata\\local\\temp\\pip-build\\gdal\\setup.py';exec(compile(open(_
_file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\u
sers\jnunn\appdata\local\temp\pip-f7tgze-record\install-record.txt --single-vers
ion-externally-managed failed with error code 1 in c:\users\jnunn\appdata\local\
temp\pip-build\gdal
Storing complete log in C:\Users\jnunn\pip\pip.log

C:\Users\jnunn\Desktop>

我以前也尝试过使用easy_install,但它返回了一个常见错误:

c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\xlocale(342) : war
ning C4530: C++ exception handler used, but unwind semantics are not enabled. Sp
ecify /EHsc

extensions/gdal_wrap.cpp(2853) : fatal error C1083: Cannot open include file: 'c
pl_port.h': No such file or directory

error: command '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.ex
e"' failed with exit status 2

加上以下额外的 pip.log:

    Exception information:
Traceback (most recent call last):
File "C:\Python26\ArcGIS10.1\lib\site-packages\pip\basecommand.py", line 107, in main
status = self.run(options, args)
File "C:\Python26\ArcGIS10.1\lib\site-packages\pip\commands\install.py", line 261, in run
requirement_set.install(install_options, global_options)
File "C:\Python26\ArcGIS10.1\lib\site-packages\pip\req.py", line 1166, in install
requirement.install(install_options, global_options)
File "C:\Python26\ArcGIS10.1\lib\site-packages\pip\req.py", line 589, in install
cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
File "C:\Python26\ArcGIS10.1\lib\site-packages\pip\util.py", line 612, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command C:\Python26\ArcGIS10.1\python.exe -c "import setuptools;__file__='c:\\users\\jnunn\\appdata\\local\\temp\\pip-build\\gdal\\setup.py';exec(compile(open(__file__).read().replace('\r    \n', '\n'), __file__, 'exec'))" install --record c:\users\jnunn\appdata\local\temp\pip-f7tgze-record\install-record.txt --single-version-externally-managed failed with error code 1 in c:\users\jnunn\appdata    \local\temp\pip-build\gdal
4

6 回答 6

6

这个问题看起来非常类似于Python GDAL 包在通过 pip 安装时缺少头文件,这似乎有工作解决方案

这里解释了具有 CPython 扩展的 python 库的常见问题,解决方案通常是:

通过下载并运行 Windows 二进制包来安装库。

于 2013-05-18T22:20:24.583 回答
4

最简单的方法(如 JF Sebastian 所建议)是从http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal安装

于 2013-12-14T05:11:51.557 回答
2

问题是 Python 认为安装在 C:\Python\ 上,但事实并非如此,因为它位于portablepython 目录中。我使用链接解决了这个问题。

例如,我的portablepython 目录(或示例中的kivy 目录)是这样的:

C:\Users\blabla.KMS\kivy-1.8.0-py3.3-win32\Python33

进入dos提示符并输入:

mklink /d c:\Python33\ C:\Users\blabla.KMS\kivy-1.8.0-py3.3-win32\Python33\ 

比你可以进入 c:\Python33\Scripts 并使用 PIP 或 easy_install 最后你可以使用以下方法删除链接:

rmdir Python33

凉爽的!我在kivy上安装了Django!

于 2014-06-19T14:26:44.830 回答
1

这不是 Python 问题,而是在 Windows 上编译源代码的问题。

我假设您按照安装说明首先安装了 GDAL 二进制文件和头文件?

此外,您可以查看指向可以帮助您的ubuntu 论坛的这个 SO question的答案。

于 2012-09-20T14:49:41.693 回答
0

我遇到了同样的问题,但我需要安装“ebooklib”模块,该模块不在http://www.lfd.uci.edu/~gohlke/pythonlibs的模块列表中。同时我下载了这个模块。但是使用 ebooklib 的 setup.py 安装失败并使用 error: command '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.ex e"' failed with exit status 2 Finnally,我已经从 lfd.uci.edu 分别安装了所有依赖模块,之后使用 setup.py 安装成功。

于 2015-06-10T22:00:35.100 回答
0

尝试在没有 anaconda 的情况下安装 ipython 时遇到了类似的问题。第一个 pip 在执行 pip install jupyter 时找不到“cl.exe”,在添加到 PATH 后,我得到了失败,退出状态为 2 错误。

您可以尝试使用 VS 文件来使其正常工作,但对我来说最简单的方法是:

1) 从https://pypi.python.org/pypi下载 .tar.gz 文件 2) 在文件夹中提取 3) 在从 cmd 提取的文件夹中运行 setup.py:

c:\> cd <wherever your extracted folder is from .tar.gz that contains setup.py>
c:\<yourcdhere>>python setup.py install

请注意,如果像我一样,您在 PATH 中没有 python,因为您有 python 32b 和 64b 用于不同的东西,您将不得不手动指向 python(将第二个命令更改为):

c:\<yourcdhere>>pythoninstallpath\python setup.py install

它将自动复制库并将其所有依赖项安装在相应 lib 文件夹下的 python 安装位置。

这样你就可以看到它是如何工作的,这是给我的。但更改目录以匹配您使用的任何内容:

我在“L:\python\py27_32b\ipython-5.3.0”处有 ipython 的 setup.py 提取的文件夹,在“L:\python\py27_32b\install”处安装了 python

c:\users\vlox>L:
L:\>cd "python\py27_32b\ipython-5.3.0"
L:\python\py27_32b\ipython-5.3.0>L:\python\py27_32b\install\python setup.py install

瞧!

希望这可以帮助

于 2017-04-05T15:35:20.390 回答