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]#
浙公网安备 33010602011771号