我不认为这是重复的,但实际上这个问题在 pip GitHub 存储库问题列表中讨论过。
注意: 根据您要安装的软件包,您可能需要修改解决方案中引用的命令。在下面的例子中,我试图设置 virtualenv 和 virtualwrapper。如果您在安装 aws-cli 或任何其他软件包时失败,只需将其插入脚本
问题的核心与 Apple 与 El Capitan 一起提供的新 SIP 相关。更具体地说,
OS X 10.11 的 python 保留了自己的六个副本,这是不可删除的,因为 Apple 对其 python 发行版进行了修改。1.4.1 不是最新的,1.10.0 是。它也出现在他们的 python 导入路径的早期,因此它通常会覆盖您安装的更高版本。
我建议现在使用不同的 python。Python.org,或通过 Homebrew 或 Anaconda Python 安装。
Ask Different Stack Exchange 上进行了非常详细的讨论,其中涵盖了自 El Capitan 最初版本以来如何识别、解决和发展 SIP 的问题。虽然我觉得它很吸引人,但您按照以下说明花费的时间比阅读它所花费的时间要少,所以我建议您在完成以下操作后查看它...
我在尝试升级 VirtualEnv 和 VirtualEnvWrapper 时遇到了完全相同的错误。在上面的线程上有几个建议,但最后最稳定的是
- 利用对 sudo OPTION 的内置支持来指定 HOME 环境变量
$ 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.
- 利用 pip 的选项强制升级并忽略任何预先存在的包
$ 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).
首先,我最初的尝试和错误:
$ 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'
解决方案
它需要以三种特定方式修改我的安装命令:
- 我不得不将
-H
标志添加到sudo
- 我必须在要
--upgrade
升级的软件包名称之后添加选项(virtualenv
)
- 我必须使用
--ignore-installed
标志并指定six
包是要忽略的包。
- *注意:通用命令是
$ sudo -H pip install <packagename> --upgrade --ignore-installed six
- 替换<packagename>
为您需要安装的特定包`
最终工作示例
第一次升级 virtualenv
$ 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
第二次升级 virtualenvwrapper
$ 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