python虛擬環(huán)境完美部署教程
一、前言
預(yù)處理
建議仔細(xì)看完本文章之后在進(jìn)行操作,避免失誤,本環(huán)境可以用于生產(chǎn)環(huán)境,有利于生產(chǎn)環(huán)境python之間的環(huán)境隔離,互相不會(huì)產(chǎn)生環(huán)境沖突;pyenv
和pyenv-virtualenv
可以完美結(jié)合使用,具體使用情況看項(xiàng)目具體要求;
依賴環(huán)境要求
yum install readline readline-devel readline-static -y yum install openssl openssl-devel openssl-static -y yum install sqlite-devel -y yum install bzip2-devel bzip2-libs -y yum install libffi-devel -y
二、pyenv安裝
pyenv獲取
[root@tset ~]# git clone https://github.com/yyuu/pyenv.git ~/.pyenv Cloning into '/root/.pyenv'... remote: Enumerating objects: 17352, done. remote: Total 17352 (delta 0), reused 0 (delta 0), pack-reused 17352 Receiving objects: 100% (17352/17352), 3.37 MiB | 24.00 KiB/s, done. Resolving deltas: 100% (11818/11818), done.
配置pyenv系統(tǒng)環(huán)境
[root@tset ~]# vim ~/.bashrc ## add by liuchao at 20190806 //添加以下內(nèi)容 export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" //保存退出 [root@tset ~]# source ~/.bashrc //執(zhí)行配置生效
三、pyenv使用
pyenv 安裝python版本
個(gè)人建議:自己在python官網(wǎng)下載想要安裝的版本;首先要在pyenv目錄下創(chuàng)建cache文件夾,用來存放python安裝包。(可以解決下載安裝慢的問題)
[root@tset ~]# mkdir ~/.pyenv/cache //創(chuàng)建cache文件夾,將下載的python安裝包存放, [root@tset ~]# cd ~/.pyenv/cache/ [root@tset cache]# ls //python安裝包后綴名必須是.tar.xz Python-2.7.16.tar.xz Python-3.7.3.tar.xz pyenv install [root@tset cache]# cd [root@tset ~]# pyenv install 3.7.3 -v /tmp/python-build.20190806095432.10104 ~ /tmp/python-build.20190806095432.10104/Python-3.7.3 /tmp/python-build.20190806095432.10104 ~ Installing Python-3.7.3... checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking for python3.7... no checking for python3... no checking for python... python checking for --enable-universalsdk... no checking for --with-universal-archs... no checking MACHDEP... checking for --without-gcc... no checking for --with-icc... no checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /usr/bin/grep checking for a sed that does not truncate output... /usr/bin/sed checking for --with-cxx-main=<compiler>... no checking for g++... no configure:
檢查是否安裝成功
[root@tset ~]# pyenv versions * system (set by /root/.pyenv/version) 3.7.3
更新數(shù)據(jù)庫
[root@tset ~]# pyenv rehash
pyenv切換python版本
[root@tset ~]# pyenv global 2.7.8 // 全局 [root@tset ~]# pyenv local 2.7.8 // 當(dāng)前目錄下 [root@tset ~]# pyenv shell 2.7.8 // shell版本 [root@tset ~]# pyenv shell --unset // 取消當(dāng)前的shell設(shè)定的版本 #創(chuàng)建墊片路徑(為所有已安裝的可執(zhí)行文件創(chuàng)建 shims,如:~/.pyenv/versions/*/bin/*,因此,每當(dāng)你增刪了 Python 版本或帶有可執(zhí)行文件的包(如 pip)以后,都應(yīng)該執(zhí)行一次本命令) [root@tset ~]# pyenv rehash
安裝與卸載
[root@tset ~]# pyenv install -l # 查看可安裝的版本 [root@tset ~]# pyenv install 2.7.8 # 安裝python2.7.8的版本 [root@tset ~]# pyenv rehash # 安裝模塊后 [root@tset ~]# pyenv pyenv uninstall 2.7.8 # 卸載
四、pyenv-virtualenv
安裝pyenv-virtualenv
[root@tset ~]# git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv Cloning into '/root/.pyenv/plugins/pyenv-virtualenv'... remote: Enumerating objects: 2064, done. remote: Total 2064 (delta 0), reused 0 (delta 0), pack-reused 2064 Receiving objects: 100% (2064/2064), 580.31 KiB | 17.00 KiB/s, done. Resolving deltas: 100% (1413/1413), done.
環(huán)境配置
[root@tset ~]# echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile [root@tset ~]# source ~/.bash_profile
使用方法
[root@tset ~]# pyenv virtualenv 2.7.10 env-2.7.10 //創(chuàng)建虛擬環(huán)境 [root@tset ~]# pyenv activate env-2.7.10 //激活虛擬環(huán)境 [root@tset ~]# pyenv deactivate //退出虛擬環(huán)境 [root@tset ~]# pyenv uninstall env-2.7.10 //刪除虛擬環(huán)境 [root@tset ~]# rm -rf ~/.pyenv/versions/env-2.7.10 //刪除真實(shí)目錄
總結(jié)
以上所述是小編給大家介紹的python虛擬環(huán)境完美部署教程,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
- Pipenv一鍵搭建python虛擬環(huán)境的方法
- Linux(Redhat)安裝python3.6虛擬環(huán)境(推薦)
- 使用Python搭建虛擬環(huán)境的配置方法
- centos 安裝python3.6環(huán)境并配置虛擬環(huán)境的詳細(xì)教程
- ubuntu環(huán)境下python虛擬環(huán)境的安裝過程
- python虛擬環(huán)境virtualenv的安裝與使用
- 用virtualenv建立多個(gè)Python獨(dú)立虛擬開發(fā)環(huán)境
- Python虛擬環(huán)境virtualenv的安裝與使用詳解
- Ubuntu下創(chuàng)建虛擬獨(dú)立的Python環(huán)境全過程
- Linux安裝Python虛擬環(huán)境virtualenv的方法
相關(guān)文章
詳解Python排序算法的實(shí)現(xiàn)(冒泡,選擇,插入,快速)
這篇文章主要為大家介紹了Python中常見的四種排序算法的實(shí)現(xiàn):冒泡排序、選擇排序、插入排序和快速排序,文中通過圖片詳細(xì)講解了它們實(shí)現(xiàn)的原理與代碼,需要的可以參考一下2022-04-04極簡(jiǎn)Python庫CherryPy構(gòu)建高性能Web應(yīng)用實(shí)例探索
今天為大家介紹的是 CherryPy,它是一個(gè)極簡(jiǎn)、穩(wěn)定且功能強(qiáng)大的Web框架,可以幫助開發(fā)者快速構(gòu)建高性能的 Web 應(yīng)用程序,使用 CherryPy,你可以輕松地創(chuàng)建RESTful API、靜態(tài)網(wǎng)站、異步任務(wù)和 WebSocket 等應(yīng)用2024-01-01python 讀txt文件,按‘,’分割每行數(shù)據(jù)操作
這篇文章主要介紹了python 讀txt文件,按‘,’分割每行數(shù)據(jù)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07PYTHON壓平嵌套列表的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)硪黄狿YTHON壓平嵌套列表的簡(jiǎn)單實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-06-06用pushplus+python監(jiān)控亞馬遜到貨動(dòng)態(tài)推送微信
這篇文章主要介紹了用pushplus+python監(jiān)控亞馬遜到貨動(dòng)態(tài)推送微信的示例,幫助大家利用python搶購商品,感興趣的朋友可以了解下2021-01-01python 產(chǎn)生token及token驗(yàn)證的方法
今天小編就為大家分享一篇python 產(chǎn)生token及token驗(yàn)證的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-12-12python 實(shí)現(xiàn)圖片旋轉(zhuǎn) 上下左右 180度旋轉(zhuǎn)的示例
今天小編就為大家分享一篇python 實(shí)現(xiàn)圖片旋轉(zhuǎn) 上下左右 180度旋轉(zhuǎn)的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-01-01