【问题标题】:six cannot be imported/uninstalled/reinstalled/upgraded六、无法导入/卸载/重装/升级
【发布时间】:2018-08-09 14:57:44
【问题描述】:

我正在尝试在我的 MacBook 终端上运行 lldb,但出现与 six 包相关的错误:

File "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python/lldb/__init__.py", line 98, in <module>
    import six
ImportError: No module named six
Traceback (most recent call last):
  File "<string>", line 1, in <module>

我尝试从终端启动python,然后执行import six,但仍然:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named six

下一步是卸载并重新安装six,但似乎与此软件包相关的所有内容对我来说都已损坏:

$: pip uninstall six
Uninstalling six:
  /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info
Proceed (y/n)? y
Exception:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/uninstall.py", line 59, in run
    requirement_set.uninstall(auto_confirm=options.yes)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req.py", line 1035, in uninstall
    req.uninstall(auto_confirm=auto_confirm)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req.py", line 598, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req.py", line 1836, in remove
    renames(path, new_path)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/util.py", line 295, in renames
    shutil.move(old, new)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
    os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/_c/lj7t1035563flfh7fy4m3gfh0000gn/T/pip-YQdNMp-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

Storing debug log for failure in /Users/lab5/.pip/pip.log

$: pip install --ignore-installed six
Downloading/unpacking six
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement six
Cleaning up...
No distributions at all found for six
Storing debug log for failure in /Users/lab5/.pip/pip.log

我下载了six并从tar.gz文件中安装了它,但似乎还是安装了旧版本:

$: pip install --ignore-installed ~/Downloads/six-1.5.1.tar.gz
Unpacking ./Downloads/six-1.5.1.tar.gz
  Running setup.py (path:/var/folders/_c/lj7t1035563flfh7fy4m3gfh0000gn/T/pip-zqLhAa-build/setup.py) egg_info for package from file:///Users/lab5/Downloads/six-1.5.1.tar.gz

    no previously-included directories found matching 'documentation/_build'
Installing collected packages: six
  Running setup.py install for six

    no previously-included directories found matching 'documentation/_build'
Successfully installed six
Cleaning up...

$: pip show six
---
Name: six
Version: 1.4.1
Location: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Requires:

Python version: Python 2.7.15
Pip version: pip 1.5.6 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (python 2.7)

您对我有什么建议可以摆脱这些错误并正确运行lldb 吗?我接受了某人的建议再次安装python(简单地brew install python),但没有帮助。

【问题讨论】:

  • 您是否尝试过为pip 安装带有--user 标志的six
  • brew install python 可能不会将新安装的 Python 放在你的路径前面,因此它不起作用。
  • @MisterMiyagi 我做了,不幸的是同样的结果

标签: python macos python-2.7 pip six


【解决方案1】:

您使用的是python2,要使用brew安装python2需要添加@2

 brew install python@2

我使用 brew 安装的 python2 并且能够安装六个就好了。从您的错误来看,当您尝试pip install six 时,您得到了OSError: [Errno 1] Operation not permitted:

尝试使用sudo -H 运行 pip

sudo -H pip install six --upgrade

【讨论】:

  • 试过了,同样的问题
【解决方案2】:

我仍然不确定错误的原因是什么,但我可以在升级我的 python 版本后摆脱它们,我很好。

要安装新的 python 版本:

brew install python

然后,我删除了/usr/local/bin/python的链接,并再次将其设置为新版本:

rm /usr/local/bin/python
ln -s /usr/local/Cellar/python/3.7.0/bin/python3.7 /usr/local/bin/python

然后,用新版本的pip安装six

python -m pip install six

(执行 python -m 强制使用新 pip 进行安装,对于新 python)

我不是 100% 喜欢那个解决方案,我仍然需要删除旧版本才能安装干净的 python,但至少我现在可以使用 lldb,这是我的主要目标

【讨论】:

    【解决方案3】:

    使用xcode-select -switch 指向正确的 Xcode 安装为我解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2022-01-03
      • 2016-04-27
      • 1970-01-01
      • 2014-01-31
      • 2021-09-21
      • 2019-11-18
      • 1970-01-01
      • 2011-11-15
      • 2015-04-06
      相关资源
      最近更新 更多