使用 ArcGIS 安装的 Python 2.7 安装 pip [英] Installing pip using ArcGIS-installed Python 2.7

查看:128
本文介绍了使用 ArcGIS 安装的 Python 2.7 安装 pip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Windows 8.1 上为 Python 2.7 安装 Scrapy,我知道我首先需要安装 pip.由于我通过ArcGIS 10.2安装了Python,所以我认为需要在C:\Python27\ArcGIS10.2\lib\site-packages下安装pip.在该目录中安装 pip 后,我会收到错误代码:

<预><代码>>>>导入点回溯(最近一次调用最后一次):文件<交互式输入>",第 1 行,在 <module> 中文件C:\Python27\ArcGIS10.2\lib\site-packages\pip\__init__.py",第 10 行,在 <module> 中从 pip.util 导入 get_installed_distributions, get_prog文件C:\Python27\ArcGIS10.2\lib\site-packages\pip\util.py",第 18 行,在 <module> 中从 pip._vendor.distlib 导入版本文件C:\Python27\ArcGIS10.2\lib\site-packages\pip\_vendor\distlib\version.py",第 14 行,在 中从 .compat 导入 string_types文件C:\Python27\ArcGIS10.2\lib\site-packages\pip\_vendor\distlib\compat.py",第 38 行,在 中从 HTMLParser 导入 HTMLParser文件C:\Python27\ArcGIS10.2\lib\HTMLParser.py",第 47 行,在 <module> 中""", re.VERBOSE)文件C:\Python27\ArcGIS10.2\lib\re.py",第190行,编译返回_compile(模式,标志)_compile 中的文件C:\Python27\ArcGIS10.2\lib\re.py",第 242 行引发错误,v # 无效的表达式错误:没有什么可重复的

我还在 C:\Python27\lib\site-packages 中安装了 pip.但是,当它仅安装在该目录中时,PyScripter 无法识别它已安装.有人有什么建议吗?

解决方案

我遇到了同样的问题,我通过重新安装 Python 解决了这个问题.

我的ArcGIS版本又从10.2.2到10.3再到10.2再到10.2.2.当通过添加/删除程序删除 ArcGIS(或仅 Python 功能)时,C:\Python27 中的大部分文件将被删除.但是,这不会从您的系统文件夹中删除 python dll.根据您的 Window 操作系统,它将是:

  • C:\Windows\System32\python27.dll
  • C:\Windows\SysWOW64\python27.dll

手动删除DLL,然后重新安装python.

这应该会给你一个真正干净的 python 安装,然后再次运行你的 get-pip.py,pip 应该按预期工作!

附言如果您要降级 Python,则删除 dll 非常重要.由于 python27.dll 似乎在 python 升级时被替换,但在降级时不会.因此,python27.dll 与 C:\Python27 中的脚本不兼容.

I'm trying to install Scrapy for Python 2.7 on Windows 8.1 and I understand that I first need pip to be installed. Since I have Python installed through ArcGIS 10.2, I think that I need to install pip under C:\Python27\ArcGIS10.2\lib\site-packages. Once pip is installed in that directory I receive the error code:

>>> import pip
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python27\ArcGIS10.2\lib\site-packages\pip\__init__.py", line 10, in <module>
    from pip.util import get_installed_distributions, get_prog
  File "C:\Python27\ArcGIS10.2\lib\site-packages\pip\util.py", line 18, in <module>
    from pip._vendor.distlib import version
  File "C:\Python27\ArcGIS10.2\lib\site-packages\pip\_vendor\distlib\version.py", line 14, in <module>
    from .compat import string_types
  File "C:\Python27\ArcGIS10.2\lib\site-packages\pip\_vendor\distlib\compat.py", line 38, in <module>
    from HTMLParser import HTMLParser
  File "C:\Python27\ArcGIS10.2\lib\HTMLParser.py", line 47, in <module>
    """, re.VERBOSE)
  File "C:\Python27\ArcGIS10.2\lib\re.py", line 190, in compile
    return _compile(pattern, flags)
  File "C:\Python27\ArcGIS10.2\lib\re.py", line 242, in _compile
    raise error, v # invalid expression
error: nothing to repeat

I've also installed pip in C:\Python27\lib\site-packages. However, when it is only installed in that directory PyScripter doesn't recognize that it is installed. Does anyone have any suggestions?

解决方案

I had the same problem, and I solved it by doing a really CLEAN reinstall of python.

My version of ArcGIS has gone up and down from 10.2.2 to 10.3 to 10.2 to 10.2.2 again. When ArcGIS (or just the Python features) is removed via Add/Remove Programs, most of the files from C:\Python27 will be removed. However, this will not remove the python dll from your system folder. Depending on your Window OS, it will be either:

  • C:\Windows\System32\python27.dll
  • C:\Windows\SysWOW64\python27.dll

Remove the DLL manually, and then do the python install again.

This should give your a really clean install of python, then run your get-pip.py again, and pip should work as expected!

P.S. The removing of the dll is really important if you are downgrading your python. As the python27.dll seem to get replaced if python is upgraded, but not when it is downgraded. Hence, there is incompatibility between python27.dll with the scripts in C:\Python27.

这篇关于使用 ArcGIS 安装的 Python 2.7 安装 pip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆