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. PHPExcel读取Excel文件的实现代码

    <?php require_once 'PHPExcel.php'; /**对excel里的日期进行格式转化*/ function GetData($val){ $jd = GregorianT ...

  2. Tomcat配置错误导致Quartz执行两次问题

    以下基于tomcat服务器 我们通常将域名映射到指定服务器的端口上,以通过域名直接访问服务,如http://www.abc.com域名已绑定到本机的80端口,项目名wechat,则直接访问http:/ ...

  3. ado.net中,数据的批量处理

    //btBigImport按钮点击事件 private void btBigImport_Click(object sender, RoutedEventArgs e)        { //连接字符 ...

  4. 用ant组建测试框架

    有时候由于公司网络或其它原因,无法采用maven,这时ant是一个比较理想的选择.以下是以ant为例,搭建一个测试框架 项目结构如下图: build.properties代码如下: # The sou ...

  5. Bootstrap CSS概览代码文字标注篇

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  6. QM UML状态机建模实例之移植 cortex-m0

    ---恢复内容开始--- 在上一期“Blinky for cortex-m0”中我们介绍了如何在QM中建立一个工程和生成代码,如何使生成的代码在我们的工程师运行起来,为此这一期要介绍如何将QP-NAN ...

  7. 支付宝即时到账API,网站收到回调页面,输出验证失败,log中responseTxt=错误的问题

    看了网上无外乎这三种原因导致: 1.参数编码问题 2.参数多余问题 3.网络延时问题 以上三种可以参考这个网站给出的解决办法:http://blog.csdn.net/zj53hao/article/ ...

  8. 一步一步搭框架(asp.netmvc+easyui+sqlserver)-02

    一步一步搭框架(asp.netmvc+easyui+sqlserver)-02 我们期望简洁带前台代码,如下: <table id="dataGrid" class=&quo ...

  9. web 调用WCF 每次都要重新编译才能正常使用 终于解决了

    项目中不知从何时起出现了个奇怪的问题,每次运行web都要全部重新编译解决方案,否则单独编译web,总是会出现WCF 调用失败的情况(什么无法激活服务,什么协议对地址不可用啊,七七八八的问题),因为这个 ...

  10. Qt中文乱码解决思路

    最近项目中遇到不少的Qt中文乱码的问题,主要原因是客户的需求比较多,Qt版本有用4的版本的也有用5的版本,并且还有windows与linux跨平台的需求.经常出现个问题是windows的解决了,源代码 ...