centos7 安装使用virtualenvwrapper
技术积累 Python Linux

virtualenvwrapper是Ian Bicking的virtualenv工具的一组扩展。扩展包括用于创建和删除虚拟环境以及管理开发工作流程的包装程序,从而使一次处理多个项目变得更加容易,而不会在其依赖项中引入冲突。

特征
1、在一个地方组织所有虚拟环境
2、包装程序,用于管理您的虚拟环境(创建,删除,复制)
3、使用单个命令在环境之间切换
4、使用虚拟环境作为参数的命令的制表符完成
5、所有操作的用户可配置钩子
6、用于创建更多可共享扩展的插件系统

如果用virtualenv 每次切换虚拟环境就要source之前虚拟环境bin目录,如果有很多就需要都记住这些目录,所以就用virtualenvwrapper来统一管理,而且省去了每次都要切换的麻烦

安装使用(python2版本)

#centos默认没有pip命令,需要安装
[root@localhost ~]# wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum install python-pip -y
[root@localhost ~]# pip install --upgrade pip

#安装virtualenvwrapper
[root@localhost ~]# pip install virtualenvwrapper

#确认下文件路径
[root@localhost ~]# which python
/usr/bin/python
[root@localhost ~]# find / -name virtualenvwrapper.sh
/usr/bin/virtualenvwrapper.sh

#添加配置
[root@localhost ~]# vim ~/.bashrc
······
#添加配置
WORKON_HOME=~/.virtualenvs  #虚拟环境统一管理目录
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python #虚拟环境对应的python版本
source /usr/bin/virtualenvwrapper.sh #执行virtualenvwrapper安装脚本

#生效配置
[root@localhost ~]# source ~/.bashrc 
virtualenvwrapper.user_scripts creating /root/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/get_env_details
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkproject

#创建虚拟环境
[root@localhost ~]# mkvirtualenv test
created virtual environment CPython2.7.5.final.0-64 in 695ms
  creator CPython2Posix(dest=/root/.virtualenvs/test, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/root/.local/share/virtualenv/seed-app-data/v1.0.1)
  activators PythonActivator,CShellActivator,FishActivator,PowerShellActivator,BashActivator
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/get_env_details
(test) [root@localhost ~]# deactivate 

[root@localhost ~]# mkvirtualenv test-1
created virtual environment CPython2.7.5.final.0-64 in 379ms
  creator CPython2Posix(dest=/root/.virtualenvs/test-1, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/root/.local/share/virtualenv/seed-app-data/v1.0.1)
  activators PythonActivator,CShellActivator,FishActivator,PowerShellActivator,BashActivator
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/get_env_details
(test-1) [root@localhost ~]# deactivate

#切换虚拟环境
[root@localhost ~]# workon test
(test) [root@localhost ~]# deactivate 
[root@localhost ~]# workon test-1
(test-1) [root@localhost ~]# deactivate 

centos7 安装使用virtualenvwrapper


安装使用(python3版本 Linux下Python3.x版本安装

#安装virtualenvwrapper
[root@localhost ~]# pip3 install --upgrade pip
[root@localhost ~]# pip3 install virtualenvwrapper

#确认下文件路径
[root@localhost ~]# which python3
/usr/local/python38/bin/python3
[root@localhost ~]# find / -name virtualenvwrapper.sh
/usr/local/python38/bin/virtualenvwrapper.sh


#添加配置
[root@localhost ~]# vim ~/.bashrc
······
#添加配置
WORKON_HOME=~/.virtualenvs  #虚拟环境统一管理目录
VIRTUALENVWRAPPER_PYTHON=/usr/local/python38/bin/python3 #虚拟环境对应的python版本
source /usr/local/python38/bin/virtualenvwrapper.sh #执行virtualenvwrapper安装脚本

#生效配置
[root@localhost ~]# source ~/.bashrc
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkproject
virtualenvwrapper.user_scripts creating /root/.virtualenvs/initialize
virtualenvwrapper.user_scripts creating /root/.virtualenvs/premkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postmkvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/prermvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postrmvirtualenv
virtualenvwrapper.user_scripts creating /root/.virtualenvs/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/get_env_details

创建虚拟环境

[root@localhost ~]# mkvirtualenv test
created virtual environment CPython3.8.2.final.0-64 in 343ms
  creator CPython3Posix(dest=/root/.virtualenvs/test, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/root/.local/share/virtualenv/seed-app-data/v1.0.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test/bin/get_env_details
(test) [root@localhost ~]# deactivate 
[root@localhost ~]# mkvirtualenv test-1
created virtual environment CPython3.8.2.final.0-64 in 339ms
  creator CPython3Posix(dest=/root/.virtualenvs/test-1, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/root/.local/share/virtualenv/seed-app-data/v1.0.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/predeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/postdeactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/preactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/postactivate
virtualenvwrapper.user_scripts creating /root/.virtualenvs/test-1/bin/get_env_details
(test-1) [root@localhost ~]# deactivate

#切换虚拟环境
[root@localhost ~]# workon test
(test) [root@localhost ~]# deactivate 
[root@localhost ~]# workon test-1
(test-1) [root@localhost ~]# deactivate 
[root@localhost ~]# 

centos7 安装使用virtualenvwrapper


一些命令操作

#创建并激活虚拟环境
mkvirtualenv

#切换虚拟环境
workon
#退出虚拟环境
deactivate

#删除虚拟环境
rmvirtualenv

#查看所有的虚拟环境
lsvirtualenv


↓↓↓进入虚拟环境后的操作 ↓↓↓
#切换到虚拟环境的目录
cdvirtualenv

#切换到虚拟环境的site-packages目录
cdsitepackages

#查看虚拟环境site-packages目录的文件
lssitepackages

本文最后记录时间 2024-03-30
文章链接地址:
https://wojc.cn/archives/578.html
本站文章除注明[转载|引用|来源],均为本站原创内容,转载前请注明出处
使用腾讯云CDN的SDK 用脚本去刷新URL缓存
统计文本中每个字符出现的次数
Nali 离线ip数据库文件
苹果CMS v10内容管理系统搭建

Python3添加支持ssl模块

Typecho替换默认Gravatar头像地址

留言

顶部