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 ...
随机推荐
- webstorm关闭vim模式
- Python 调试工具PySnooper
相信很多小伙伴平时写python的时候都是需要调试程序的,出问题了,需要了解函数内部是怎么跑的,而这个时候很多人都会想到在疑惑的地方使用print函数来打印一下参数来调试.虽然用print也是不失为是 ...
- Win10 企业版 激活 批处理
cd %SystemRoot%\System32 wscript.exe slmgr.vbs /upk wscript.exe slmgr.vbs /ipk NPPR9-FWDCX-D2C8J-H87 ...
- 阻止移动端input按钮聚焦时唤起软键盘的方法
一.设置input为readonly 二.使用JS代码,在input按钮fous时就让其blur
- restful规范与rest_framework
django两种开发模式: 一.前后端不分离项目 二.前后端分离项目 什么是restful规范? 在前后端不分离的项目中,网页所需要的数据可以直接通过模板渲染的方式传递到前端页面,并且可以很好的支持d ...
- poj1696(极角排序,贪心)
---恢复内容开始--- 题目链接:https://vjudge.net/problem/POJ-1696 题意:有n个点,规定起点,每次只能向左走,不能与之前的路径交叉,求最多能经过几个点. 思路: ...
- Double write Buffer的配置
InnoDB和XtraDB使用称为doublewrite缓冲区的特殊功能来提供数据损坏的强大保证.想法是在写入数据文件之前将数据写入主表空间中的顺序日志.如果发生部分页面写入(换句话说,写入损坏),I ...
- ES使用小结之索引Rollover
Elasticsearch 使用小结之索引Rollover 索引名 一般而言,客户端将数据每天写入一个索引,比如直接写入YYYY-MM-HH格式的索引,那么我们只需要在写入的客户端里面获取时间,然后得 ...
- 如何配置虚拟机的ip地址以及如何使用XShell和WinSCP工具
参考资料:https://blog.csdn.net/phy1997/article/details/78928796
- abstract class 与 interface
abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制,正是由于这两种机制的存在,才赋予了Java强大的面向对象能力. abstract class和inte ...