首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在OS Capitan上,我不能升级依赖于6个兼容性实用程序的python包,也不能删除6个

在OS Capitan上,我不能升级依赖于6个兼容性实用程序的python包,也不能删除6个
EN

Stack Overflow用户
提问于 2015-10-17 09:47:05
回答 4查看 15.7K关注 0票数 34

我试着用刮擦法,但我有个问题。

从six.moves导入xmlrpc_client作为xmlrpclib ImportError:无法导入名称xmlrpc_client

然后,我尝试了pip install --upgrade six scrape,但是:

代码语言:javascript
复制
  Found existing installation: six 1.4.1
    DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 211, in main
status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 311, in run
root=options.root_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 640, in install
requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 716, in uninstall
paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 125, in remove
renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 315, in renames
shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
  File "/System/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/3h/r_2cxlvd1sjgzfgs4xckc__c0000gn/T/pip-5h86J8-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
EN

回答 4

Stack Overflow用户

发布于 2015-11-08 21:13:21

快速修复:

我刚解决了我认为同样的问题。您可以考虑尝试此方法(如有必要,请执行以下操作):

pip install scrape --upgrade --ignore-installed six

Github最终是我得到这个答案的地方(如果这个答案不能解决您的问题,您还可以考虑更多的建议)。这似乎也是个卡皮坦人的问题。

而且,从技术上讲,这可能是一个复制。但另一篇文章给出的答案是安装自己的Python,而不是依赖默认的osx,这让我觉得更费劲。

Longer,Real:

最后,我遇到了一种情况,为了安装其他库,我实际上需要升级six,这时忽略是不够的。对我来说升级6的最简单的方法是不使用pip,而是手动从六页下载六页,解压缩,转移到新解压缩的六个包目录,然后手动运行安装(如果需要的话,sudo):

python setup.py install

感谢这个答案的指导。

票数 52
EN

Stack Overflow用户

发布于 2016-03-15 21:11:05

我不认为这是重复的,但实际上是此问题在pip GitHub存储库问题列表中进行了讨论。

注意:取决于您安装的包,您可能需要修改解决方案中引用的命令。在下面的例子中,我试图设置虚拟包装器和虚拟包装器。如果安装aws或其他软件包失败,只需将其插入脚本中即可。

问题的核心在于苹果公司与El Capitan一起推出的新SIP。更多的具体来说

OSX10.11的python保留了自己的6个版本,这是不可移除的,因为苹果对python发行版做了一些修改。1.4.1不是最新的,1.10.0是最新的。它也在python导入路径的早期出现,因此它通常会覆盖您安装的后续版本。 我建议现在使用另一条蟒蛇。Python.org的,或通过Homebrew或Anaconda Python安装的。

有一个关于Ask不同堆栈交换的极其详细的讨论,它涵盖了自El最初版本以来如何识别、解决和发展SIP的问题。虽然我觉得它很吸引人,但是你会花更少的时间按照下面的说明来阅读它,所以我会在你完成下面的内容后重新检查它。

在试图升级VirtualEnv & VirtualEnvWrapper时,我遇到了完全相同的错误。上面有几个建议,但最后最稳定的是

  1. 利用sudo选项的内置支持来指定HOME环境变量。
代码语言:javascript
复制
$ man sudo

  -H   The -H (HOME) option option sets the HOME environment variable 
        to the home directory of the target user (root by default) as specified 
        HOME environment variable depends on sudoers(5) settings.  By default, 
        sudo will set HOME if env_reset or always_set_home are set, or if
        set_home is set and the -s option is specified on the command line.
  1. 利用pip的选项强制升级,忽略任何预先存在的包
代码语言:javascript
复制
$ pip install --help | grep upgrade

  -U, --upgrade   Upgrade all specified packages to the newest available 
        version. This process is recursive regardless of whether a dependency 
        is already satisfied.

beejhuff@ignatius:~/mac_setup$ pip install --help | grep ignore-installed

  -I, --ignore-installed  Ignore the installed packages (reinstalling instead).

First,我最初的尝试和错误:

代码语言:javascript
复制
$ sudo pip install virtualenv virtualenvwrapper

The directory '/Users/beejhuff/Library/Caches/pip/http' or its parent directory 
is not owned by the current user and the cache has been disabled. 
Please check the permissions and owner of that directory. If executing 
pip with sudo, you may want sudo's -H flag.

The directory '/Users/beejhuff/Library/Caches/pip' or its parent directory 
is not owned by the current user and caching wheels has been disabled. 
check the permissions and owner of that directory. If executing pip with 
sudo, you may want sudo's -H flag.

Collecting virtualenv
  Downloading virtualenv-15.0.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 335kB/s 
Collecting virtualenvwrapper
  Downloading virtualenvwrapper-4.7.1-py2.py3-none-any.whl
Collecting virtualenv-clone (from virtualenvwrapper)
  Downloading virtualenv-clone-0.2.6.tar.gz
Collecting stevedore (from virtualenvwrapper)
  Downloading stevedore-1.12.0-py2.py3-none-any.whl
Collecting pbr>=1.6 (from stevedore->virtualenvwrapper)
  Downloading pbr-1.8.1-py2.py3-none-any.whl (89kB)
    100% |████████████████████████████████| 92kB 362kB/s 
Collecting six>=1.9.0 (from stevedore->virtualenvwrapper)
  Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: virtualenv, virtualenv-clone, pbr, six, stevedore, virtualenvwrapper
  Running setup.py install for virtualenv-clone ... done
  Found existing installation: six 1.4.1
    DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/commands/install.py", line 317, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/req/req_set.py", line 726, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/req/req_install.py", line 746, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip-8.1.0-py2.7.egg/pip/utils/__init__.py", line 267, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/System/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: '/tmp/pip-GQL8Gi-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

解决方案

它需要以三种特定的方式修改我的安装命令:

  1. 我必须将-H标志添加到sudo
  2. 我必须在升级包的名称之后添加--upgrade选项(virtualenv)
  3. 我必须使用--ignore-installed标志并指定要忽略的six包。
  4. *注意:通用命令是$ sudo -H pip install <packagename> --upgrade --ignore-installed six --用安装所需的特定包替换<packagename>

最终工作示例

第1次升级虚拟主机

代码语言:javascript
复制
$ sudo -H pip install virtualenv --upgrade --ignore-installed six

Password:

Collecting virtualenv
  Using cached virtualenv-15.0.0-py2.py3-none-any.whl
Collecting six
  Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: virtualenv, six
Successfully installed six-1.4.1 virtualenv-15.0.0

第二次升级虚拟包装器

代码语言:javascript
复制
$ sudo -H pip install virtualenvwrapper --upgrade --ignore-installed six

Password:

  Downloading virtualenvwrapper-4.7.1-py2.py3-none-any.whl
Collecting six
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting virtualenv (from virtualenvwrapper)
  Downloading virtualenv-15.0.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 751kB/s 
Collecting virtualenv-clone (from virtualenvwrapper)
  Downloading virtualenv-clone-0.2.6.tar.gz
Collecting stevedore (from virtualenvwrapper)
  Downloading stevedore-1.12.0-py2.py3-none-any.whl
Collecting pbr>=1.6 (from stevedore->virtualenvwrapper)
  Downloading pbr-1.8.1-py2.py3-none-any.whl (89kB)
    100% |████████████████████████████████| 92kB 417kB/s 
Installing collected packages: virtualenv, virtualenv-clone, pbr, six, stevedore, virtualenvwrapper
  Running setup.py install for virtualenv-clone ... done
Successfully installed pbr-1.8.1 six-1.4.1 stevedore-1.12.0 virtualenv-15.0.0 virtualenv-clone-0.2.6 virtualenvwrapper-4.7.1
票数 20
EN

Stack Overflow用户

发布于 2016-09-16 15:29:44

以前的两个答案对我都不起作用。最后,我从GitHub,aws/aws获得了解决方案,如下所示。

在OS上,如果您看到El Capitan中distutils附带的六种版本的错误,请使用 $ sudo pip安装awscli -忽略-安装了6个

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33185147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档