MAC系统下安装的Python神器之一virtualenv 和 virtualenvwrapper遇到的问题和解决方法

安装virtualenv和virtualenvwrapper时报错:

JazzdeMacBook-Air:~ jazzli$ sudo pip install virtualenv

The directory '/Users/jazzli/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/jazzli/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.

Requirement already satisfied: virtualenv in /Library/Python/2.7/site-packages

JazzdeMacBook-Air:~ jazzli$ sudo pip install virtualenvwrapper

The directory '/Users/jazzli/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/jazzli/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 virtualenvwrapper

  Downloading virtualenvwrapper-4.8.2-py2.py3-none-any.whl

Requirement already satisfied: virtualenv in /Library/Python/2.7/site-packages (from virtualenvwrapper)

Collecting stevedore (from virtualenvwrapper)

  Downloading stevedore-1.28.0-py2.py3-none-any.whl

Collecting virtualenv-clone (from virtualenvwrapper)

  Downloading virtualenv-clone-0.2.6.tar.gz

Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /Library/Python/2.7/site-packages (from stevedore->virtualenvwrapper)

Collecting six>=1.10.0 (from stevedore->virtualenvwrapper)

  Downloading six-1.11.0-py2.py3-none-any.whl

Installing collected packages: six, stevedore, virtualenv-clone, 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-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main

    status = self.run(options, args)

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run

    prefix=options.prefix_path,

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 778, in install

    requirement.uninstall(auto_confirm=True)

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall

    paths_to_remove.remove(auto_confirm)

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove

    renames(path, new_path)

  File "/Library/Python/2.7/site-packages/pip-9.0.1-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-AJ8fd9-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

1. Mac系统默认是没有安坟装pip安装工具,在终端运行以下命令

sudo  easy-install pip

2. 设定环境变量:

vi ~/.bash_profile

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
退出保存
3.执行生效
source ~/.bash_profile

4.测试创建目录

JazzdeMacBook-Air:~ jazzli$ mkvirtualenv testdir

 

5.查看创建的虚拟环境目录

JazzdeMacBook-Air:~ jazzli$ workon

testdir




posted @ 2018-02-03 23:02  \牛魔王/  阅读(215)  评论(0)    收藏  举报