真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

python虛擬環(huán)境virtualenv和virtualenvwrapper

1.virtualenv

揚(yáng)中ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!

virtualenv作用:在一個(gè)操作系統(tǒng)下使用不同的python環(huán)境,包括不同的python版本和不同的python庫(kù)包


安裝pip

[root@sht-sgmhadoopcm-01 software]# wgethttps://bootstrap.pypa.io/get-pip.py --no-check-certificate

[root@sht-sgmhadoopcm-01 software]# python get-pip.py


安裝virtualenv

[root@sht-sgmhadoopcm-01 software]# pip install virtualenv


創(chuàng)建虛擬環(huán)境test1_env

默認(rèn)新建的虛擬環(huán)境包括pip、easy_install等工具

[root@sht-sgmhadoopcm-01 software]# virtualenv test1_env

New python executable in /opt/software/test1_env/bin/python

Installing setuptools, pip, wheel...

done.


會(huì)生成響應(yīng)的目錄和文件

[root@sht-sgmhadoopcm-01 software]# ls -lh test1_env/

total 0

drwxr-xr-x 2 root root 268 Feb 12 17:30 bin

drwxr-xr-x 3 root root  23 Feb 12 17:30 include

drwxr-xr-x 3 root root  23 Feb 12 17:30 lib

lrwxrwxrwx 1 root root   3 Feb 12 17:30 lib64 -> lib


啟用虛擬環(huán)境

這個(gè)環(huán)境下執(zhí)行python相關(guān)的操作都是限定在虛擬環(huán)境中

[root@sht-sgmhadoopcm-01 software]# source test1_env/bin/activate

(test1_env) [root@sht-sgmhadoopcm-01 software]#


查看當(dāng)前虛擬環(huán)境的python目錄是否正確

>>> import sys

>>> print sys.path

['', '/opt/software/test1_env/lib64/python27.zip', '/opt/software/test1_env/lib64/python2.7', '/opt/software/test1_env/lib64/python2.7/plat-linux2', '/opt/software/test1_env/lib64/python2.7/lib-tk', '/opt/software/test1_env/lib64/python2.7/lib-old', '/opt/software/test1_env/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7', '/usr/lib/python2.7', '/opt/software/test1_env/lib/python2.7/site-packages']


退出虛擬環(huán)境

(test1_env) [root@sht-sgmhadoopcm-01 bin]# deactivate


測(cè)試1:在系統(tǒng)環(huán)境中安裝第三方庫(kù),虛擬環(huán)境沒有影響

[root@sht-sgmhadoopcm-01 software]# pip install jinja2

[root@sht-sgmhadoopcm-01 software]# pip list|grep Jinja2

Jinja2   

[root@sht-sgmhadoopcm-01 software]# source test1_env/bin/activate

(test1_env) [root@sht-sgmhadoopcm-01 software]# pip list|grep jinja2|wc -l

0


測(cè)試2:在虛擬環(huán)境中安裝第三方庫(kù),系統(tǒng)環(huán)境沒有影響

[root@sht-sgmhadoopcm-01 software]# source test1_env/bin/activate

(test1_env) [root@sht-sgmhadoopcm-01 software]# pip install futures

(test1_env) [root@sht-sgmhadoopcm-01 software]# pip list|grep futures

futures    3.2.0  

[root@sht-sgmhadoopcm-01 software]# pip list |grep futures|wc -l

0


2.virtualenvwrapper

virtualenvwrapper作用:集中管理虛擬環(huán)境


安裝virtualenvwrapper

[root@sht-sgmhadoopcm-01 software]# pip install virtualenvwrapper

[root@sht-sgmhadoopcm-01 ~]# vim ~/.bash_profile

export WORKON_HOME=$HOME/.virtualenvs

export PROJECT_HOME=$HOME/workspace

source /bin/virtualenvwrapper.sh

[root@sht-sgmhadoopcm-01 ~]# source ~/.bash_profile


新建虛擬環(huán)境:mkvirtualenv [虛擬環(huán)境名稱]

[root@sht-sgmhadoopcm-01 software]# mkvirtualenv test3_env

New python executable in /root/.virtualenvs/test3_env/bin/python

Installing setuptools, pip, wheel...

done.

virtualenvwrapper.user_scripts creating /root/.virtualenvs/test3_env/bin/predeactivate

virtualenvwrapper.user_scripts creating /root/.virtualenvs/test3_env/bin/postdeactivate

virtualenvwrapper.user_scripts creating /root/.virtualenvs/test3_env/bin/preactivate

virtualenvwrapper.user_scripts creating /root/.virtualenvs/test3_env/bin/postactivate

virtualenvwrapper.user_scripts creating /root/.virtualenvs/test3_env/bin/get_env_details


[root@sht-sgmhadoopcm-01 software]# mkvirtualenv test4_env


列出虛擬環(huán)境列表:workon或者lsvirtualenv

[root@sht-sgmhadoopcm-01 .virtualenvs]# workon

test3_env

test4_env


啟動(dòng)/切換虛擬環(huán)境:workon [虛擬環(huán)境名稱]

[root@sht-sgmhadoopcm-01 .virtualenvs]# workon test3_env

(test3_env) [root@sht-sgmhadoopcm-01 .virtualenvs]# workon test4_env


刪除虛擬環(huán)境:rmvirtualenv [虛擬環(huán)境名稱]

(test4_env) [root@sht-sgmhadoopcm-01 .virtualenvs]# rmvirtualenv test3_env


網(wǎng)頁(yè)名稱:python虛擬環(huán)境virtualenv和virtualenvwrapper
文章位置:http://weahome.cn/article/jdhjos.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部