虚拟环境它是一个虚拟化,从电脑独立开辟出来的环境。就是借助虚拟机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的更多相关文章

  1. python开发学习-day01 (python安装与版本、字符串、字典、运算符、文件)

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  2. python编程学习--Pygame - Python游戏编程入门(0)---转载

    原文地址:https://www.cnblogs.com/wuzhanpeng/p/4261015.html 引言 博客刚开,想把最近学习的东西记录下来,算是一种笔记.最近打算开始学习Python,因 ...

  3. python 笔记2:python语法基础

    python语法学习笔记: 1 输入输出 input(),print(). name = input('input your name : ')print('hello ,'+name)print(& ...

  4. Python笔记·第一章—— Python基础(一)

    一.Python的简介 1.Python的由来与版本 1.1 python的由来 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文 ...

  5. Python语言学习之Python入门到进阶

    人们常说Python语言简单,编写简单程序时好像也确实如此.但实际上Python绝不简单,它也是一种很复杂的语言,其功能特征非常丰富,能支持多种编程风格,在几乎所有方面都能深度定制.要想用好Pytho ...

  6. Python基础学习之Python主要的数据分析工具总结

    Python主要是依靠众多的第三方库来增强它的数据处理能力的.常用的是Numpy库,Scipy库.Matplotlib库.Pandas库.Scikit-Learn库等. 常规版本的python需要在安 ...

  7. 【python+selenium学习】Python常见错误之:IndentationError: unexpected indent

    初入python+selenium学习之路,总会遇到这样那样的问题.IndentationError: unexpected indent,这个坑我已经踏进数次了,索性记录下来.都知道Python对代 ...

  8. python笔记:#001#python简介

    认识 Python 人生苦短,我用 Python -- Life is short, you need Python 目标 Python 的起源 为什么要用 Python? Python 的特点 Py ...

  9. Python+Selenium学习--设置等待时间

    场景 sleep():设置固定休眠时间.python 的time 包提供了休眠方法sleep() ,导入time 包后就可以使用sleep()进行脚本的执行过程进行休眠.implicitly_wait ...

随机推荐

  1. scalaTest的初步使用

    1. 概述 ScalaTest是scala生态系统中最流行和灵活的测试工具,可以测试scala.js.java代码. 2. ScalaTest的特性 a. ScalaTest的核心是套件(suite) ...

  2. python3 正则表达式 re模块之辣眼睛 计算器

    额...学到几个常用模块了,也要其中考试了,每天晚上敲一点,敲得脑壳疼,不过又想到好一点的办法了,有时间再改吧. 此非吾所欲也,实属无奈也....复习之路漫漫,吾将到书上求索,在此不多逗留,我挥一挥衣 ...

  3. Guava源码阅读-base-Enums

    package com.google.common.base; guava源码中对这个类的方法介绍只有一句话: Utility methods for working with {@link Enum ...

  4. 【贪心科技】贪心科技内容合伙人关于AI公司及创业的演讲笔记

    贪心科技内容合伙人关于AI公司及创业的演讲笔记 视频 目录 一.投资角度对 AI 的两个基本认知 二.简单分析 AI 公司的两个纬度四个层面 三.AI 垂直行业应用的三点中美对比 四.给创业者的四个建 ...

  5. nginx+uwsgi02---django部署(推荐)

    参考  https://blog.csdn.net/weixin_39198406/article/details/79277580 https://www.cnblogs.com/alex3714/ ...

  6. SQL SERVER 根据字段名称批量设置为主键

    --设置主键 --alter table 你的表名 add constraint pk_s primary key (id) SELECT 'alter table ' + TABLE_NAME + ...

  7. 1.3.3 并发容器类MAP/LIST/SET/QUEUE

    HashMap 下标计算方法:hashCode & (length-1) ,&按位与操作,二进制相同位都是1,该位才为1 JDK1.7与JDK1.8中HashMap区别: JDK1.8 ...

  8. pandas合并excel文件

    现在有多个excel 文件,需要对其进行合并 import pandas as pd path='' list1=[] #save data data=pd.read_excel(path,dtype ...

  9. php 栈、 出栈、入栈

    最近在面试的时候被问到栈,回来做个总结,希望对大家有帮助 栈是线性表的一种,他的特点是后入先出,可以这么理解,栈就像一个存东西的盒子,先放进去的在最底层,后放进去的在上层,因为上层的东西把底层的东西压 ...

  10. 数据分析—win7+ipython+notebook安装

    先安装python 3.x 然后 cmd 执行 pip3 ipython 然后 cmd 执行 pip3 install jupyter notebook 然后 cmd 执行 jupyter noteb ...