由于Errno 1,无法使用'--always-copy'标志设置virtualenv [英] Unable to setup virtualenv with '--always-copy' flag due to Errno 1
问题描述
我正在尝试运行此命令
$ virtualenv --always-copy venv
然后我得到了所有这些错误:
Then I got all these errors:
shutil.Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_Drag.so',
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/_Drag.so', "[Errno 1] Operation not permitted:
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/_Drag.so'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_Ctl.so',
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/_Ctl.so', "[Errno 1] Operation not permitted:
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/_Ctl.so'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/imageop.so',
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/imageop.so', "[Errno 1] Operation not permitted:
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/imageop.so'"),
('/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_Scrap.so',
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/_Scrap.so', "[Errno 1] Operation not permitted:
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/_Scrap.so'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_testcapi.so',
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/_testcapi.so', "[Errno 1] Operation not permitted:
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/_testcapi.so'"),
('/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/unicodedata.so',
'/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/unicodedata.so', "[Errno 1] Operation not permitted: '/Users/antkong/dev/zeetings/venv/lib/python2.7/lib-dynload/unicodedata.so'"),
我检查了源文件的权限.都可读
I checked the permission of the source file. It is all readable
$ ls -l '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_Drag.so'
-rwxr-xr-x 1 root wheel 55936 3 Oct 16:50 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_Drag.so
在运行命令之前,我始终确保venv不存在.
I have always ensured venv does not exist before running the command.
那为什么会失败?
版本信息:
$ python --version
Python 2.7.10
$ pip --version
pip 9.0.1 from /Library/Python/2.7/site-packages (python 2.7)
推荐答案
virtualenv使用shutil.copytree
复制文件,copytree
将使用copystat
将src文件标志复制到目标,但是macOS系统python文件具有特殊的含义标志0x80000
,普通用户甚至root用户都无法设置.
virtualenv use shutil.copytree
to copy files, copytree
will copy src file flags to destination with copystat
, but the macOS system python files have a special flag 0x80000
, which can not set by a normal user, even root.
如果您安装的带有自制软件的python没有此标志,则此命令有效.
if you installed a python with homebrew, which does not have this flag, this command would work.
更新:
根据 stat .h 0x80000
是SF_RESTRICTED
:
#define SF_RESTRICTED 0x00080000 /* restricted access */
这是优胜美地系统完整性保护的新功能.
it is something new with Yosemite System Integrity Protection.
您可能会在ls -lO
输出中看到restricted
标志:
you could see restricted
flag in with ls -lO
output:
$ ls -lO '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_Drag.so'
-rwxr-xr-x 1 root wheel restricted,compressed 55888 Jul 15 12:21 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_Drag.so
如果您尝试在命令行中进行设置:
if you try to set it in the command line:
$ sudo chflags restricted tmp
chflags: tmp: Operation not permitted
我认为python shutil.copystat
应该排除此标志,因为没有Apple赋予的特殊权利,就无法在用户区中设置它.
I think python shutil.copystat
should exclude this flag as there is no way to set it in userland without special entitlement assigned by Apple.
这篇关于由于Errno 1,无法使用'--always-copy'标志设置virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!