centos 默认安装的python是2.6版本的

使用virtualenv 环境管理工具建立python虚拟环境的时候会遇到一些错误,DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6

好像是python2.6 官方不在支持 virtualenv

1.升级python版本 到2.7

2.删除删除掉以前的setuptools,pip(/usr/bin下也要删干净)

pip uninstall setuptools
  pip uninstall pip

重新安装

下载pip

wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no-check-certificate

解压

tar -zxvf pip-1.5.4.tar.gz

cd pip-1.5.4

python setup.py install

(此时报错,找不到setuptools.)

首先安装setuptools

下载setuptools安装脚本

wget –q http://peak.telecommunity.com/dist/ez_setup.py

python ez_setup.py 执行

再次执行 python setup.py install

OK

最后使用  mkvirtualenv --help命令查看,可以使用virtualenv了

[root@localhost ~]# mkvirtualenv --help
Usage: mkvirtualenv [-a project_path] [-i package] [-r requirements_file] [virtualenv options] env_name

-a project_path

Provide a full path to a project directory to associate with
the new environment.

-i package

Install a package after the environment is created.
This option may be repeated.

-r requirements_file

Provide a pip requirements file to install a base set of packages
into the new environment.

virtualenv help:

Usage: virtualenv [OPTIONS] DEST_DIR

Options:
--version show program's version number and exit
-h, --help show this help message and exit
-v, --verbose Increase verbosity.
-q, --quiet Decrease verbosity.
-p PYTHON_EXE, --python=PYTHON_EXE
The Python interpreter to use, e.g.,
--python=python2.5 will use the python2.5 interpreter
to create the new environment. The default is the
interpreter that virtualenv was installed with
(/usr/bin/python)
--clear Clear out the non-root install and start from scratch.
--no-site-packages DEPRECATED. Retained only for backward compatibility.
Not having access to global site-packages is now the
default behavior.
--system-site-packages
Give the virtual environment access to the global
site-packages.
--always-copy Always copy files rather than symlinking.
--unzip-setuptools Unzip Setuptools when installing it.
--relocatable Make an EXISTING virtualenv environment relocatable.
This fixes up scripts and makes all .pth files
relative.
--no-setuptools Do not install setuptools in the new virtualenv.
--no-pip Do not install pip in the new virtualenv.
--no-wheel Do not install wheel in the new virtualenv.
--extra-search-dir=DIR
Directory to look for setuptools/pip distributions in.
This option can be used multiple times.
--download Download preinstalled packages from PyPI.
--no-download, --never-download
Do not download preinstalled packages from PyPI.
--prompt=PROMPT Provides an alternative prompt prefix for this
environment.
--setuptools DEPRECATED. Retained only for backward compatibility.
This option has no effect.
--distribute DEPRECATED. Retained only for backward compatibility.
This option has no effect.

但是  读入环境还是报错

[root@localhost ~]# source /root/.bashrc
/usr/local/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python and that PATH is
set properly.

查了下好像是virtualenvwrapper 版本低了的原因 升级了virtualenvwrapper

[root@localhost ~]# /usr/local/bin/pip install virtualenvwrapper --upgrade

就OK 了

建立虚拟运行环境

[root@localhost ~]# mkvirtualenv newenv

[root@localhost ~]# mkvirtualenv newenv
New python executable in /root/.virtualenvs/newenv/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /root/.virtualenvs/newenv/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/newenv/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/newenv/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/newenv/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/newenv/bin/get_env_details

从这里可以看出 新建的虚拟运行环境目录在  /root/.virtualenvs目录下, 虚拟运行环境目录是根据环境变量WORKON_HOME设定决定的

这是我的环境变量:

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
source /usr/bin/virtualenvwrapper.sh

此时进入虚拟运行环境的命令变成了 workon

[root@localhost .virtualenvs]# workon newenv
(newenv) [root@localhost .virtualenvs]#

也可以直接 cd  /root/.virtualenvs

退出环境 deactivate

(newenv) [root@localhost .virtualenvs]# deactivate
[root@localhost .virtualenvs]#

python 使用virtualenvrapper虚拟环境管理工具的更多相关文章

  1. python开发之虚拟环境管理:virtualenv、virtualenvwrapper、pycharm

    1 引言 进行Python开发时,多个项目可能使用到不同的依赖,例如A项目需要1.8版本的Django,而B项目需要2.0版本的Django,这时候如果没有使用虚拟环境,就需要来回卸载和安装Djang ...

  2. nave node 的虚拟环境管理工具

    nave 是类似python venv 的node 虚拟环境管理工具 安装 npm install -g nave 简单使用 帮助命令 Usage: nave <cmd> Commands ...

  3. pythonWeb框架创建app模块以及虚拟环境管理工具

    在进行项目搭建的时候,如果有多个功能模块,以及多个网页地址时,为了系统的可维护性,以及易读性,我们大多数情况下选择模块化开发 所以我们就要使用app指令来创建不同的功能模块 首先项目框架如下: 接下来 ...

  4. python的虚拟环境管理工具venv使用方法介绍及与nodejs的包管理方式对比

    一.nodejs 包管理方式 我们知道, nodejs的包管理工具npm可以安装项目所需要的包,安装方法及区别如下: npm i module_name -g 全局安装 npm i module_na ...

  5. Python虚拟环境管理工具virtualenvwrapper安装及配置

      1. 安装virtualenv 使用pip install virtualenv安装virtualenv虚拟环境工具 2. 安装virtualenvwrapper a) Linux环境,直接使用p ...

  6. 虚拟环境管理工具virtualenvwrapper-win初试

    virtualenv 用于建立虚拟目录,但是每次进入指定虚拟都必须activate, 而且如果一个环境很久没用了,不记得环境所在目录,就会遗忘该环境,virtualenvwrapper 正是解决以上问 ...

  7. Miniconda虚拟环境管理工具命令方法

    创建制定Python版本的虚拟环境 conda create --name 虚拟环境名称 Python=3.7.3(版本号) 进入指定虚拟环境 conda activate 虚拟环境名称 退出虚拟环境 ...

  8. anaconda虚拟环境管理,从此Python版本不用愁

    1 引言 在前几篇博文中介绍过virtualenv.virtualenvwrapper等几个虚拟环境管理工具,本篇要介绍的anaconda也有很强大的虚拟环境管理功能,甚至相比virtualenv.v ...

  9. Anaconda 包管理工具 conda 进行虚拟环境管理入门

    在基于 python 进行数据分析.机器学习等领域的实践和学习时,由于代码的更迭和更新,运行他人实现的代码或尝试安装新的工具库时往往需要指定特定版本的其他工具库,以满足特定环境的构建条件.而将同一工具 ...

随机推荐

  1. Ajax实现原理

    Ajax的工作 Ajax直觉认识:我们发送一个请求,但是这个请求比较特殊它是异步的,也就是说客户端是不会感觉到的.在发送这个请求的时候我们绑定了一个事件,这个事件会监控我们发送请求的状态,并且每次状态 ...

  2. extjs之apply

    ext.apply(Ext.Form.VTypes,{}) {}里面的内容如下: { password:function (val.field) { if(field.initialPassField ...

  3. LCD内核自带驱动分析

    分析内种LCD驱动程序框架 LCD在fbmem.c文件中1.找到init.函数 static int __initfbmem_init(void){ 做的工作: (1).if (register_ch ...

  4. HTML <label> 标签

    定义:<label> 标签为 input 元素定义标注(标记). 用法: label 元素不会向用户呈现任何特殊效果.不过,它为鼠标用户改进了可用性.如果您在 label 元素内点击文本, ...

  5. CSS布局学习笔记之position

    CSS知识点 之 position布局 前段时间被同学怂恿,参加了百度前端技术学院的一个小培训,第一个阶段下来学到不少东西.课程的第一个阶段主要是HTML5 和 CSS 基础知识的一个小培训,给出的一 ...

  6. dos2unix

    dos2unix 实际上就是把文本文件里面的^M删除,我一般懒得用这个命令,vi里面用一个命令(:%s/^m//g)删除即可. 用法举例: dos2unix a.txt b.txt 要把一批文件都do ...

  7. 使用javascript打开一个新页而不被浏览器屏蔽

    使用javascript打开一个新页面可以有几种方式,但各有利弊,以下做下分析 1.window.open(url) 这是新手最常用的方法,好处是简单易用,坏处,很简单,会被很多浏览器拦截而导致功能失 ...

  8. lightoj1348

    //Accepted 6004 KB 924 ms /* source: lightoj1348 time :2015.5.29 by :songt */ /*题解: 树链剖分 */ #include ...

  9. [蟒蛇菜谱]Python日志记录最佳实践

    # -*- coding: utf8 -*- import logging # 创建一个logger logger = logging.getLogger('mylogger') logger.set ...

  10. 操作系统和程序设计语言的API使用的字符编码分析

     1.Java的运行环境中,String是什么编码? 使用java做程序设计语言,字符编码是和jvm相关的,和操作系统无关. java默认的编码是jvm在安装的时候就确定了的,它是根据你的系统的环境确 ...