python 使用virtualenvrapper虚拟环境管理工具
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虚拟环境管理工具的更多相关文章
- python开发之虚拟环境管理:virtualenv、virtualenvwrapper、pycharm
1 引言 进行Python开发时,多个项目可能使用到不同的依赖,例如A项目需要1.8版本的Django,而B项目需要2.0版本的Django,这时候如果没有使用虚拟环境,就需要来回卸载和安装Djang ...
- nave node 的虚拟环境管理工具
nave 是类似python venv 的node 虚拟环境管理工具 安装 npm install -g nave 简单使用 帮助命令 Usage: nave <cmd> Commands ...
- pythonWeb框架创建app模块以及虚拟环境管理工具
在进行项目搭建的时候,如果有多个功能模块,以及多个网页地址时,为了系统的可维护性,以及易读性,我们大多数情况下选择模块化开发 所以我们就要使用app指令来创建不同的功能模块 首先项目框架如下: 接下来 ...
- python的虚拟环境管理工具venv使用方法介绍及与nodejs的包管理方式对比
一.nodejs 包管理方式 我们知道, nodejs的包管理工具npm可以安装项目所需要的包,安装方法及区别如下: npm i module_name -g 全局安装 npm i module_na ...
- Python虚拟环境管理工具virtualenvwrapper安装及配置
1. 安装virtualenv 使用pip install virtualenv安装virtualenv虚拟环境工具 2. 安装virtualenvwrapper a) Linux环境,直接使用p ...
- 虚拟环境管理工具virtualenvwrapper-win初试
virtualenv 用于建立虚拟目录,但是每次进入指定虚拟都必须activate, 而且如果一个环境很久没用了,不记得环境所在目录,就会遗忘该环境,virtualenvwrapper 正是解决以上问 ...
- Miniconda虚拟环境管理工具命令方法
创建制定Python版本的虚拟环境 conda create --name 虚拟环境名称 Python=3.7.3(版本号) 进入指定虚拟环境 conda activate 虚拟环境名称 退出虚拟环境 ...
- anaconda虚拟环境管理,从此Python版本不用愁
1 引言 在前几篇博文中介绍过virtualenv.virtualenvwrapper等几个虚拟环境管理工具,本篇要介绍的anaconda也有很强大的虚拟环境管理功能,甚至相比virtualenv.v ...
- Anaconda 包管理工具 conda 进行虚拟环境管理入门
在基于 python 进行数据分析.机器学习等领域的实践和学习时,由于代码的更迭和更新,运行他人实现的代码或尝试安装新的工具库时往往需要指定特定版本的其他工具库,以满足特定环境的构建条件.而将同一工具 ...
随机推荐
- Android基础:startActivityForResult 和 onActivityResult 问题
项目中用到弹出Acitivity来获得用户输入 所以用到 onActivityResult()方法接受用户输入 奇怪问题 startActivityForResult() 后直接调用 onActivi ...
- js判断是否是移动端 访问移动端网址
1以下为代码,可放置在网站foot底部文件,或者haead顶部文件,建议将代码放在网站顶部,这样可以实现手机访问立即跳转! <script src="http://siteapp.ba ...
- mac 端口被占用及kill端口
在本地部署 Web 应用时我有遇到过某网络端口已经被其他程序占用的情况,这时候就需要先退出占用该端口的进程,我们可以通过“终端”来实现结束占用某特定端口的进程 1.打开终端,使用如下命令: lsof ...
- Redis各类型应用场景
Redis的六种特性 l ,重要消息的,然后工作线程可以选择按 ret = r.zincrby("login:login_times", 1, uid) //那么如何获得登录次数最 ...
- html5移动web开发笔记(一)Web 存储
localStorage - 没有时间限制的数据存储 localStorage 方法 localStorage 方法存储的数据没有时间限制.第二天.第二周或下一年之后,数据依然可用. 用户访问页面的次 ...
- MicroERP如何配置网络应用
概述: MicroERP支持多种数据库运行,其中单机版数据库格式为Access,网络版数据库可以SQLServer.Oracle.MySQL等.以下分别以Access和SQLServer ...
- 一个无聊的python + opencv 示例
opencv不用多说,先推荐一个给力的教程: https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutor ...
- 一个Java递归删除目录的方法
public static void delDir(File f) { // 判断是否是一个目录, 不是的话跳过, 直接删除; 如果是一个目录, 先将其内容清空. if(f.isDirectory() ...
- python中转义用法 r''
代码中需要转多个字符,,可以使用 r'' 例子: print(r"'''\\sfd/;fe'lsdfl")
- 算法-QuickSort
#include <stdlib.h> #include <iostream> #include <vector> using namespace std; tem ...