[Mac] 安裝 VirtualEnv 時遇到無法移除舊版 six 的問題

[Mac] 安裝 VirtualEnv 時遇到無法移除舊版 six 的問題

今天想在 Mac 裝 virtualenv,想說照著之前的做法裝就可以了,

不料卻出現奇怪的錯誤訊息:

testuser@localhost ~ $ pip install virtualenvwrapper

......
Successfully built virtualenvwrapper virtualenv-clone
Installing collected packages: virtualenv, virtualenv-clone, pbr, six, stevedore, virtualenvwrapper
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip/wheel.py", line 323, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/virtualenv.py'

 

就算加了 sudo,還是一樣有錯誤,只是換了不同的訊息:

Installing collected packages: pbr, six, stevedore, virtualenv-clone, virtualenv, virtualenvwrapper
  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 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 778, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 754, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/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-9GSavp-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

 

研究了一下,Operation not permitted 的錯誤訊息,

似乎是在移除舊版的 six 時才跑出來的。

但執行 pip uninstall six 也是會出現一樣的訊息 …

 

最後在網路上找到了解答,好像是 Mac 預設安裝的 six 太舊,

但要移除時又會撞上 Mac 的 System Integrity Protection,導致移除失敗。

暫解的方法是忽略這個已經裝好的舊版 six,直接再裝一版新的:

testuser@localhost ~ $ sudo pip install --ignore-installed six

Collecting six
  Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six
Successfully installed six-1.10.0

 

接下來再安裝 virtualenv 就沒問題了:

testuser@localhost ~$ sudo pip install virtualenvwrapper

Collecting virtualenvwrapper
Collecting stevedore (from virtualenvwrapper)
  Downloading stevedore-1.21.0-py2.py3-none-any.whl
Requirement already satisfied: virtualenv-clone in /Library/Python/2.7/site-packages (from virtualenvwrapper)
Requirement already satisfied: virtualenv in /Library/Python/2.7/site-packages (from virtualenvwrapper)
Requirement already satisfied: pbr>=2.0.0 in /Library/Python/2.7/site-packages (from stevedore->virtualenvwrapper)
Requirement already satisfied: six>=1.9.0 in /Library/Python/2.7/site-packages (from stevedore->virtualenvwrapper)
Installing collected packages: stevedore, virtualenvwrapper
Successfully installed stevedore-1.21.0 virtualenvwrapper-4.7.2

 

參考資料:pip: Six issue when installing package

 

(本頁面已被瀏覽過 581 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料