简体   繁体   English

使用pip在python中安装模块失败

[英]Using pip to install modules in python failing

I'm having trouble installing python modules using pip. 我在使用pip安装python模块时遇到问题。 Below is the output from the command window: 以下是命令窗口的输出:

Note that I installed pip immediately before trying to install GDAL module. 请注意,我在尝试安装GDAL模块之前立即安装了pip。

I am on a w7 64bit machine running python 2.7 我在运行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>

I have tried to use easy_install before too, and it came back with a common error to this: 我之前也试过使用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

Plus the following additional pip.log: 另外还有以下额外的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

This issue looks very similar to Python GDAL package missing header file when installing via pip which seems to have working solution . 这个问题看起来非常类似于Python GDAL包缺少头文件时通过pip安装 ,似乎有工作的解决方案

Usual problem with python libraries that have CPython extensions is explained here and solution is often: 这里解释具有CPython扩展的python库的常见问题,解决方案通常是:

install library by downloading and running windows binary package. 通过下载并运行Windows二进制包来安装库。

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

The problem is that Python thinks to be installed on C:\\Python\\ but this is not true as it is inside portablepython directory. 问题是Python认为安装在C:\\ Python \\上,但这不是真的,因为它在portablepython目录中。 I resolved this using a link. 我用链接解决了这个问题。

For instance my portablepython directory (or kivy directory in example) is this: 例如,我的portablepython目录(或示例中的kivy目录)是这样的:

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

enter dos prompt and type: 输入dos提示符并键入:

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

than you can go inside c:\\Python33\\Scripts and use PIP or easy_install finally you can delete the link using: 你可以进入c:\\ Python33 \\ Scripts并使用PIP或easy_install最后你可以删除链接:

rmdir Python33

Cool! 凉! I installed Django on kivy! 我把Django安装在kivy上!

This isn't a Python problem, but an issue with the compilation of the sources on Windows. 这不是Python问题,而是在Windows上编译源代码的问题。

I assume that you followed the installation instructions and installed the GDAL binaries first, with the header files ? 我假设您遵循安装说明并首先使用头文件安装GDAL二进制文件?

Moreover, you can check the answer to this SO question which points to a ubuntu forum that could help you. 此外,您可以查看此SO问题的答案, 该问题指向可以帮助您的ubuntu论坛

I had the same problem, but i needed to install 'ebooklib' module, which is not in the list of modules at http://www.lfd.uci.edu/~gohlke/pythonlibs . 我有同样的问题,但我需要安装'ebooklib'模块,它不在http://www.lfd.uci.edu/~gohlke/pythonlibs的模块列表中。 At the same time i had this module downloaded. 同时我下载了这个模块。 But installation with ebooklib's setup.py failed with error: command '"c:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\BIN\\cl.ex e"' failed with exit status 2 Finnally, i've installed all the dependent modules separately, from lfd.uci.edu, and after that installing with setup.py was successfull. 但使用ebooklib的setup.py进行安装失败, error: command '"c:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\BIN\\cl.ex e"' failed with exit status 2最后,我安装了所有从lfd.uci.edu单独的依赖模块,然后用setup.py安装成功。

I ran into a similar problem when trying to install ipython without anaconda. 我试图在没有anaconda的情况下安装ipython时遇到了类似的问题。 First pip could not find 'cl.exe' when doing pip install jupyter and after adding to PATH, i got the failed with exit status 2 error. 在执行pip install jupyter时,第一个pip找不到'cl.exe',并且在添加到PATH之后,我得到了退出状态2错误的失败。

You could try playing around with VS files to get it to work, but the easiest way around it for me was to: 您可以尝试使用VS文件来使其工作,但对我来说最简单的方法是:

1) Download the .tar.gz file from https://pypi.python.org/pypi 2) extract in a folder 3) run setup.py in the extracted folder from cmd: 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

note if, like me, you don't have python in the PATH because you have python 32b and 64b for different things, you will have to point to python manually (change second command to): 请注意,如果像我一样,你在PATH中没有python,因为你有不同的python 32b和64b,你必须手动指向python(将第二个命令更改为):

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

and it will automatically copy the library and install all its dependencies in python install location under the appropriate lib folder. 它将自动复制库并在相应的lib文件夹下的python安装位置安装其所有依赖项。

So that you can see how it worked, here it is for me. 所以你可以看到它是如何工作的,这里适合我。 but change directories to match whatever you are using: 但更改目录以匹配您正在使用的任何内容:

i have the extracted folder with ipython's setup.py at "L:\\python\\py27_32b\\ipython-5.3.0" and python installed at "L:\\python\\py27_32b\\install" 我在“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

and voila! 瞧!

hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM