python笔记:学习设置Python虚拟环境+配置 virtualenvwarpper+创建Python3.6的虚拟环境+安装numpy
虚拟环境它是一个虚拟化,从电脑独立开辟出来的环境。就是借助虚拟机docker来把一部分内容独立出来,我们把这部分独立出来的东西称作“容器”,在这个容器中,我们可以只安装我们需要的依赖包,各个容器之间互相隔离,互不影响。在什么环境下我们需要使用到虚拟环境呢?比如,我们接手一个项目的时候,这个项目之前是在Python2.7下运行的,而你接手的项目需要在python3环境中运行,想想就应该知道,如果不使用虚拟环境,这这两个项目可能无法同时使用,使用python3则公司之前的项目可能无法运行,反正则新项目运行有麻烦。而如果虚拟环境可以分别为这两个项目配置不同的运行环境,这样两个项目就可以同时运行。

Ubuntu系统默认的Python是2.7,为了使多个Python版本共存,我们使用virtualenv/virtualenvwrapper来管理不同的Python版本和相应的软件包。
virtualenvwrapper是virtualenv的扩展,使得管理虚拟环境更加方便。
sudo pip install virtualenv virtualenvwrapper
配置 virtualenvwarpper
默认virtualenvwrapper安装在/usr/local/bin下面,实际上需要运行virtualenvwrapper.sh文件才行;所以需要先进行配置一下:
创建虚拟环境管理目录: mkdir $HOME/.virtualenvs
在~/.bashrc中添加行:
export VIRTUALENV_USE_DISTRIBUTE=1 # 总是使用 pip/distribute export WORKON_HOME=$HOME/.virtualenvs # 所有虚拟环境存储的目录
if [ -e $HOME/.local/bin/virtualenvwrapper.sh ];then
source $HOME/.local/bin/virtualenvwrapper.sh
else if [ -e /usr/local/bin/virtualenvwrapper.sh ];then
source /usr/local/bin/virtualenvwrapper.sh
fi
fi
export PIP_VIRTUALENV_BASE=$WORKON_HOME export PIP_RESPECT_VIRTUALENV=true
启动 virtualenvwrapper: source ~/.bashrc 得到如下输出:
veelion@gtx:~/opencv$ source ~/.bashrc
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/get_env_details
使用方法
使用virtualenvwrapper —help 查看所有命令,常用的有:
- 创建基本环境:mkvirtualenv [环境名]
- 删除环境:rmvirtualenv [环境名]
- 激活环境:workon [环境名]
- 退出环境:deactivate
- 列出所有环境:workon 或者 lsvirtualenv -b
创建Python3.6的虚拟环境
veelion@gtx:~$ mkvirtualenv -p python3.6 py3.6
Running virtualenv with interpreter /usr/bin/python3.6
Using base prefix '/usr'
New python executable in /home/veelion/.virtualenvs/py3.6/bin/python3.6
Also creating executable in /home/veelion/.virtualenvs/py3.6/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/py3.6/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/py3.6/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/py3.6/bin/preactivate
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/py3.6/bin/postactivate
virtualenvwrapper.user_scripts creating /home/veelion/.virtualenvs/py3.6/bin/get_env_details
安装numpy
workon py3.6
pip install numpy
文章来自于我的学习笔记www.yuanrenxue.com
python笔记:学习设置Python虚拟环境+配置 virtualenvwarpper+创建Python3.6的虚拟环境+安装numpy的更多相关文章
- python开发学习-day01 (python安装与版本、字符串、字典、运算符、文件)
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- python编程学习--Pygame - Python游戏编程入门(0)---转载
原文地址:https://www.cnblogs.com/wuzhanpeng/p/4261015.html 引言 博客刚开,想把最近学习的东西记录下来,算是一种笔记.最近打算开始学习Python,因 ...
- python 笔记2:python语法基础
python语法学习笔记: 1 输入输出 input(),print(). name = input('input your name : ')print('hello ,'+name)print(& ...
- Python笔记·第一章—— Python基础(一)
一.Python的简介 1.Python的由来与版本 1.1 python的由来 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文 ...
- Python语言学习之Python入门到进阶
人们常说Python语言简单,编写简单程序时好像也确实如此.但实际上Python绝不简单,它也是一种很复杂的语言,其功能特征非常丰富,能支持多种编程风格,在几乎所有方面都能深度定制.要想用好Pytho ...
- Python基础学习之Python主要的数据分析工具总结
Python主要是依靠众多的第三方库来增强它的数据处理能力的.常用的是Numpy库,Scipy库.Matplotlib库.Pandas库.Scikit-Learn库等. 常规版本的python需要在安 ...
- 【python+selenium学习】Python常见错误之:IndentationError: unexpected indent
初入python+selenium学习之路,总会遇到这样那样的问题.IndentationError: unexpected indent,这个坑我已经踏进数次了,索性记录下来.都知道Python对代 ...
- python笔记:#001#python简介
认识 Python 人生苦短,我用 Python -- Life is short, you need Python 目标 Python 的起源 为什么要用 Python? Python 的特点 Py ...
- Python+Selenium学习--设置等待时间
场景 sleep():设置固定休眠时间.python 的time 包提供了休眠方法sleep() ,导入time 包后就可以使用sleep()进行脚本的执行过程进行休眠.implicitly_wait ...
随机推荐
- xampp 启动mysql 显示busy
1.端口被占用问题:2.默认3306端口并没有被占用:3.删除xampp\mysql\data\下的ibdata1再重启:4.没装其他mysql.
- Ocelot 配置参数
Downstream是下游服务配置 UpStream是上游服务配置 Aggregates 服务聚合配置 ServiceName, LoadBalancer, UseServiceDiscovery 配 ...
- WINDOWS命令行关闭本地占用的端口
1.查找对应的端口占用的进程:netstat -aon|findstr "8060" ,找到占用8060端口对应的程序的PID号: netstat -aon|finds ...
- Docker使用Portainer搭建可视化界面
Portainer介绍 Portainer是Docker的图形化管理工具,提供状态显示面板.应用模板快速部署.容器镜像网络数据卷的基本操作(包括上传下载镜像,创建容器等操作).事件日志显示.容器控制台 ...
- QFramework 使用指南 2020(六):脚本生成(4)小结与补充
我们花了四篇文章,介绍了 QF 中的脚本生成功能. 实际上 QF 中的脚本生成是有两种的,第一种就是我们现在学习的 ViewController + Bind 模式. 这种模式是为除 UGUI 以外的 ...
- [Tensorflow] 使用 Mask_RCNN 完成目标检测与实例分割,同时输出每个区域的 Feature Map
Mask_RCNN-2.0 网页链接:https://github.com/matterport/Mask_RCNN/releases/tag/v2.0 Mask_RCNN-master(matter ...
- python列表删除--remove(),del,pop()
remove()参数为列表元素,若在列表中,删除,不在则报错 如: pop()不带参数时默认删除列表的末尾元素并返回该元素,带参数时该参数为列表元素的下标值 不带参数: 以下标为参数: del 后面可 ...
- CORS扫描工具
参数链接: https://github.com/chenjj/CORScanner 未发现Cors风险 已发现Cors风险 py2遇到的坑: 提示https ssl告警 /usr/local/lib ...
- C#实现隐藏手机号、邮箱、姓名等敏感信息扩展方法
还是老惯例,直接上代码. 最终效果图: public static class HideSensitiveInfoExtension { /// <summary> /// 隐藏敏感信息 ...
- Python 解LeetCode:23. Merge k Sorted Lists
题目描述:把k个排序的链表组成的列表合并成一个排序的链表 思路: 使用堆排序,遍历列表,把每个列表中链表的头指针的值和头指针本身作为一个元素放在堆中: 第一步中遍历完列表后,此时堆中最多会有n个元素, ...