虚拟环境它是一个虚拟化,从电脑独立开辟出来的环境。就是借助虚拟机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. Nginx+Keepalived双主架构实现

    Keepalived+Nginx实现高可用Web负载均衡 Master 192.168.0.69 nginx.keepalived Centos7.4backup 192.168.0.70 nginx ...

  2. Core Data概述(转)

    Core Data是一个模型层的技术.Core Data帮助你建立代表程序状态的模型层.Core Data也是一种持久化技术,它能将模型对象的状态持久化到磁盘,但它最重要的特点是:Core Data不 ...

  3. 神经网络(NN)实现多分类-----Keras实现

    IRIS数据集介绍   IRIS数据集(鸢尾花数据集),是一个经典的机器学习数据集,适合作为多分类问题的测试数据,它的下载地址为:http://archive.ics.uci.edu/ml/machi ...

  4. swift 第四课 随意 设置button 图片和文字 位置

    项目中经常遇到按钮改变文字和图片位置的情况,所以尝试写一个 button 的分类: 参照连接 http://blog.csdn.net/dfqin/article/details/37813591 i ...

  5. mac Access denied for user 'root'@'localhost' (using password: YES)

    1:苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务 2: Start it in safe mode 进入终端 输入: cd /usr/local/mysql ...

  6. golang struct组合,转型问题请教

    type Action interface { OnHurt2(other Action) GetDamage() int } type Base struct { atk, hp int } fun ...

  7. shell学习笔记1-文件安全与权限

    1,创建文件的用户和他所属的组拥有该文件,文件的属主可以设定谁具有读.写.执行该文件的权限,根用户可以改变任何普通用户的设置. 2,一个文件一经创建,就具有三种访问权限:读(可以显示该文件的内容).写 ...

  8. class.forName 和 classLoader的区别

    Java中的Class.forName()和ClassLoader都可以用来对类进行加载.Class.forName()除了将类的.class文件加载到JVM中 还会对类进行解释,执行类中的stati ...

  9. 1.3.4 Fork/Join框架

    package com.study.forkjoin; import java.util.ArrayList; import java.util.List; import java.util.conc ...

  10. TypeScript 解构

    ⒈解构数组 最简单的解构莫过于数组的解构赋值了: let input = [1, 2]; let [first, second] = input; console.log(first); // out ...