Mac上的Python / PIP软管

时间:2018-10-31 21:36:21

标签: python macos pip

我认为Python的系统安装可以。我可以轻松地从bash打开python shell。但是,PIP已不再。我也在尝试运行Ansible,但只是退出了工作。

我正在做的是试图解决模块安装但无法导入的问题。我先卸载然后重新安装,这解决了我的大多数问题,然后一切都崩溃了。

问题1:PIP不见了。 PIP显示“找不到命令”。那么也许符号链接消失了?我尝试通过https://pip.readthedocs.io/en/latest/installing/重新安装并获得以下信息:

Traceback (most recent call last):
  File "get-pip.py", line 28, in <module>
    import tempfile
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

当尝试使用easy_install时,出现以下错误:

Traceback (most recent call last):
  File "/usr/bin/easy_install-2.7", line 11, in <module>
    load_entry_point('setuptools==18.5', 'console_scripts', 'easy_install')()
  File "/Users/farroar/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 484, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Users/farroar/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2725, in load_entry_point
    return ep.load()
  File "/Users/farroar/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2343, in load
    return self.resolve()
  File "/Users/farroar/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2349, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 46, in <module>
    from setuptools.archive_util import unpack_archive
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/archive_util.py", line 15, in <module>
    from pkg_resources import ensure_directory, ContextualZipFile
ImportError: cannot import name ContextualZipFile

-a python提供的内容:

/usr/local/bin/python
/usr/bin/python

我用brew安装了python并重新安装,但在此过程中收到错误:

error: could not delete '/usr/local/lib/python2.7/site-packages/pip/_internal/configuration.py': Permission denied
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall python@2`

当我尝试在不假设root用户的情况下运行ansible时,出现奇怪的错误:

.....
", line 18, in <module>
    from cryptography.x509.name import Name
  File "/usr/local/lib/python2.7/site-packages/cryptography/x509/name.py", line 28, in <module>
    _ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
TypeError: 'type' object is not iterable

我希望在这里有一些指导。一切工作正常,直到遇到无法加载的模块。把它追到一个洞里。

2 个答案:

答案 0 :(得分:0)

  1. 运行:list

  2. 您是否使用alist安装了Python。如果您这样做了,请which pip查看是否存在未链接的文件。

  3. 尝试直接使用brew运行应用程序。

答案 1 :(得分:0)

有时候,如果您用足够长的时间敲击它,它只会让步。我再次卸载了brew python安装程序。在那之后,我能够安装pip。都很奇怪酿造的东西弄乱了一切。

我真的甚至需要将brew用于python吗?我只是在猜测是否需要使用2.7.10以外的版本,对吗?