前言:继续安装中,这节记录 mac 安装 python 虚拟环境,多版本共存...

1. 安装 pip -- python的包管理工具:

sudo easy_install pip 

安装成功,出现下面:

2. 安装完pip之后,就要安装 virtualenv:

sudo pip install virtualenv  # 卸载安装:sudo pip uninstall virtualenv

据说如果是用的macOS 10.11可能会出现以下的提示(我用的是macOS 10.13,也出现以下的提示):

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

可以忽略,或者执行下面的命令(其实它已经在提示的最后建议要加上 -H):

sudo -H pip install virtualenv

3. 然后要安装virtualenvwrapper:

Virtaulenvwrapper 是 virtualenv 的扩展包,可以更方便地新增,删除,复制,切换虚拟环境。

sudo -H pip install virtualenvwrapper

安装成功如下:

据说,有人在安装的时候,遇到了这样的错误(我未遇到,未验证):

 Installing collected packages: six
Found existing installation: six 1.4.
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.:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py", line , in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py", line , in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line , in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line , in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_uninstall.py", line , in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py", line , in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line , in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line , in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line , in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno ] Operation not permitted: '/tmp/pip-vyEme3-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

执行下面的命令,重新安装:

 sudo pip install pbr
sudo pip install --no-deps stevedore
sudo pip install --no-deps virtualenvwrapper

4. 创建虚拟环境:

source /usr/local/bin/virtualenvwrapper.sh

5. 让文件生效,并且要将命令写到 ~.bash_profile 里。

创建虚拟环境,指定python的版本,并将虚拟环境命名为python3

mkvirtualenv --python=/usr/local/bin/python3 python3 

6. 创建好虚拟环境之后,会自动进入虚拟环境

退出虚拟环境的命令为 deactivate

虚拟环境的一些命令:

workon   会列出所有的虚拟环境

workon  [name]  会进入指定的虚拟环境

deactivate   退出当前的虚拟环境

mkvirtualenv  [name] 创建虚拟环境

rmvirtualenv  [name] 删除虚拟环境

参考:https://blog.csdn.net/blog_user_zk/article/details/72844452

mac 下 python 虚拟环境的安装和配置的更多相关文章

  1. mac环境下Python虚拟环境的安装和配置

    虚拟环境(virtualenv) 安装:在终端输入 pip install virtualenv 如果没安装pip会出现 pip: command not found,此时需要进行 sudo easy ...

  2. Python虚拟环境的安装和配置-virtualenv与windows下多个python版本共存

    Python虚拟环境的安装和配置-virtualenv与windows下多个python版本共存 windows下多个python版本共存 https://www.python.org/downloa ...

  3. ubuntu系统下Python虚拟环境的安装和使用

    ubuntu系统下Python虚拟环境的安装和使用        前言:进行python项目开发的时候,由于不同的项目需要使用不同的资源包和相关的配置,因此创建多个python虚拟环境,在虚拟环境下开 ...

  4. linux系统下Python虚拟环境的安装和使用

    前言:进行python项目开发的时候,由于不同的项目需要使用不同的资源包和相关的配置,因此创建多个python虚拟环境,在虚拟环境下开发就显得很有必要. 安装虚拟环境 步骤: 打开Linux终端(快捷 ...

  5. python为何需要虚拟环境--Python虚拟环境的安装和配置-virtualenv

    一 虚拟环境 virtual environment 它是一个虚拟化,从电脑独立开辟出来的环境.通俗的来讲,虚拟环境就是借助虚拟机docker来把一部分内容独立出来,我们把这部分独立出来的东西称作“容 ...

  6. ubuntu环境下python虚拟环境的安装

    一. 虚拟环境搭建 在开发中安装模块的方法: pip install 模块名称 之前我们安装模块都是直接在物理环境下安装,这种安装方法,后面一次安装的会覆盖掉前面一次安装的.那如果一台机器上面开发多个 ...

  7. MAC下go语言的安装和配置

    Mac下安装一些文件都是比较简单的.安装了brew以后,很多的程序只要一条命令就搞定了. brew install go 安装好go语言以后主要是配置go_path,和go_root的地址. go_r ...

  8. mac下,redis的安装与配置

    一.安装redis 1.到官网下载redis最新版本号,我下载的是3.0.3 http://redis.io/ 2.拷贝redis-3.0.3到/usr/local文件夹 3.解压缩sudo tar ...

  9. windows下python虚拟环境virtualenv安装和使用

    前面介绍了python在ubuntu16.04环境下,python的虚拟环境virtualenv的安装,下面介绍在windows环境下的安装和使用. 环境信息 操作系统:windows10 pytho ...

随机推荐

  1. C#设计模式原则

    原则的诞生:面向对象:封装.继承.多态三大支柱蕴含了用抽象来封装变化,降低耦合,实现复用的精髓: 封装:隐藏内部的实现,保护内部信息: 继承:实现复用,归纳共性: 多态:改写对象行为,实现更高级别的继 ...

  2. thinkphp 3.2.3 - App.class.php 解析

    class App { public static function init() { load_ext_file(COMMON_PATH); // { // /home/www/www.domain ...

  3. selenium中webdriver跳转新页面后定位置新页面的两种方式

    刚刚在写Python爬虫的时候用到了selenium , 在跳转新页面时发现无法定位新页面 , 查找不到新页面的元素 一番查询后得到了解决方法 , 便记录下来备忘 , 也与大家分享 # 页面跳转代码. ...

  4. Python9-MySQL-MySQL-ORM框架-day48

    ORM框架:AQLAlchemy-作用: 1.提供简单的规则 2.自动转换成SQL语句 -DB first: 手动创建数据库以及表 -> ORM框架 -> 自动生成类 code first ...

  5. C++学习网站——www.cplusplus.com

    http://www.cplusplus.com/ 有各个函数.语法的实例代码,可以在线运行http://cpp.sh/不支持中文字符,不错.

  6. HDU:4417-Super Mario(离线线段树)

    Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...

  7. HDOJ 2120 Ice_cream's world I

    Ice_cream's world I ice_cream's world is a rich country, it has many fertile lands. Today, the queen ...

  8. cf976d Degree Set

    ref #include <algorithm> #include <iostream> #include <cstdio> #include <vector ...

  9. IBOutletCollection 索引获取顺序问题

    在sb中绑定了一个IBOutletCollection后,根据索引获取元素发现和自己拖线时的顺序不同,有时又会根据顺序,不知道是xcode的bug还是本身就是无序的. 在使用的时候直接排序: - (v ...

  10. 设计模式之第1章-工厂方法模式(Java实现)

    设计模式之第1章-工厂方法模式(Java实现) “我先来”,“不,老公,我先!”.远远的就听到几个人,哦不,是工厂方法模式和抽象工厂模式俩小夫妻在争吵,尼妹,又不是吃东西,谁先来不都一样(吃货的世界~ ...