当前位置: 首页 > news >正文

mac 下 python 虚拟环境的安装和配置

    前言:继续安装中,这节记录 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,也出现以下的提示):

1 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.  
2 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

安装成功如下:

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

 1 Installing collected packages: six  
 2   Found existing installation: six 1.4.1  
 3     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.  
 4     Uninstalling six-1.4.1:  
 5 Exception:  
 6 Traceback (most recent call last):  
 7   File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py", line 215, in main  
 8     status = self.run(options, args)  
 9   File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py", line 317, in run  
10     prefix=options.prefix_path,  
11   File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line 736, in install  
12     requirement.uninstall(auto_confirm=True)  
13   File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 742, in uninstall  
14     paths_to_remove.remove(auto_confirm)  
15   File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove  
16     renames(path, new_path)  
17   File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py", line 267, in renames  
18     shutil.move(old, new)  
19   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move  
20     copy2(src, real_dst)  
21   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2  
22     copystat(src, dst)  
23   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat  
24     os.chflags(dst, st.st_flags)  
25 OSError: [Errno 1] 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'  

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

1 sudo pip install pbr  
2 sudo pip install --no-deps stevedore  
3 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

 

转载于:https://www.cnblogs.com/ostrich-sunshine/p/8782596.html

相关文章:

  • 操作系统概念(一)进程,线程,多线程
  • 20165301 2017-2018-2 《Java程序设计》第七周学习总结
  • Gym101350 FMonkeying Around
  • thinkphp5项目--企业单车网站(七)
  • Go初接触之image
  • linux系统安装telnet服务
  • ztree连接数据库,实现下拉菜单
  • c++之enum的好处与 define 的区别
  • 利用itext导出PDF的小例子
  • Linux 防火墙开放特定端口 (iptables)
  • kafka知识体系-kafka数据可靠性和一致性保证
  • 结对编程收获
  • Ojective-C学习笔记(4)关于面向对象编程
  • I函数
  • 猫狗大战
  • 网络传输文件的问题
  • [原]深入对比数据科学工具箱:Python和R 非结构化数据的结构化
  • Akka系列(七):Actor持久化之Akka persistence
  • E-HPC支持多队列管理和自动伸缩
  • electron原来这么简单----打包你的react、VUE桌面应用程序
  • iBatis和MyBatis在使用ResultMap对应关系时的区别
  • Invalidate和postInvalidate的区别
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • Node项目之评分系统(二)- 数据库设计
  • spring学习第二天
  • ucore操作系统实验笔记 - 重新理解中断
  • 从零到一:用Phaser.js写意地开发小游戏(Chapter 3 - 加载游戏资源)
  • 给自己的博客网站加上酷炫的初音未来音乐游戏?
  • 设计模式 开闭原则
  • 硬币翻转问题,区间操作
  • ​中南建设2022年半年报“韧”字当头,经营性现金流持续为正​
  • #单片机(TB6600驱动42步进电机)
  • #鸿蒙生态创新中心#揭幕仪式在深圳湾科技生态园举行
  • $.ajax()
  • $emit传递多个参数_PPC和MIPS指令集下二进制代码中函数参数个数的识别方法
  • (1)常见O(n^2)排序算法解析
  • (13)[Xamarin.Android] 不同分辨率下的图片使用概论
  • (C#)if (this == null)?你在逗我,this 怎么可能为 null!用 IL 编译和反编译看穿一切
  • (附源码)计算机毕业设计SSM教师教学质量评价系统
  • (排序详解之 堆排序)
  • (十一)JAVA springboot ssm b2b2c多用户商城系统源码:服务网关Zuul高级篇
  • (一)u-boot-nand.bin的下载
  • (转)visual stdio 书签功能介绍
  • .java 指数平滑_转载:二次指数平滑法求预测值的Java代码
  • .net core 连接数据库,通过数据库生成Modell
  • .Net Core 中间件验签
  • .NET NPOI导出Excel详解
  • .NET 除了用 Task 之外,如何自己写一个可以 await 的对象?
  • .Net转Java自学之路—SpringMVC框架篇六(异常处理)
  • .project文件
  • /proc/vmstat 详解
  • /ThinkPHP/Library/Think/Storage/Driver/File.class.php  LINE: 48
  • @synthesize和@dynamic分别有什么作用?
  • [20170728]oracle保留字.txt
  • [ASP.NET MVC]如何定制Numeric属性/字段验证消息