问题
I am trying to run this command
$ 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
I have always ensured venv does not exist before running the command.
So why the failure?
Version info:
$ python --version
Python 2.7.10
$ pip --version
pip 9.0.1 from /Library/Python/2.7/site-packages (python 2.7)
回答1:
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.
if you installed a python with homebrew, which does not have this flag, this command would work.
Update:
according to stat.h 0x80000
is SF_RESTRICTED
:
#define SF_RESTRICTED 0x00080000 /* restricted access */
it is something new with Yosemite System Integrity Protection.
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
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.
来源:https://stackoverflow.com/questions/46781050/unable-to-setup-virtualenv-with-always-copy-flag-due-to-errno-1