如何搭建Python生产环境pyenv和pipenv
这篇文章主要介绍了如何搭建Python生产环境pyenv和pipenv,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。
基于debian:
$cat/proc/versionLinuxversion4.19.0-6-amd64(debian-kernel@lists.debian.org)(gccversion8.3.0(Debian8.3.0-6))#1SMPDebian4.19.67-2(2019-08-28)
一、Pyenv
1. 能做什么
可以基于用户修改全局python的版本。
支持每个项目对应不同的python版本。
2. 简单说明
可以通过设置PATH来改变当前shell session的python版本:pyenv shell.
可以通过配置项目所在目录的.python-version文件来指定项目使用的python版本。你也可以使用pyenv local命令来修改这个文件指定的python版本。这个文件会首先在当前目录查找,如果没有找到,会继续往上层目录递归寻找。
可以修改$(pyenv root)/version来指定系统默认的python版本,可以通过pyenv global修改。
3. 安装 pyenv
参考自:https://github.com/pyenv/pyenv-installer
curlhttps://pyenv.run|bash#按照提示,将下面三行添加到~/.bashrc文件中#Loadpyenvautomaticallybyadding#thefollowingto~/.bashrc:exportPYENV_ROOT="$HOME/.pyenv"exportPATH="/home/kyan/.pyenv/bin:$PATH"eval"$(pyenvinit-)"eval"$(pyenvvirtualenv-init-)"#重启shell环境exec$SHELL#更新pyenvupdate#卸载,还需要删除添加到bashrc文件中的那几行rm-fr~/.pyenv
4. 安装和删除指定的python版本
#安装#在安装python之前,最好安装下面的包,不然会有"Missingctypes"错误sudoapt-getinstalllibffi-devsudoapt-getinstalllibbz2-devsudoapt-getinstalllibreadline-devsudoapt-getinstalllibsqlite3-devpyenvinstall3.8.0#删除pyenvuninstall3.8.0#详细命令参数,可以参考helpkyan@kyanvultrtokyo0:~$pyenvpyenv1.2.15Usage:pyenv<command>[<args>]Someusefulpyenvcommandsare:commandsListallavailablepyenvcommands--versionDisplaytheversionofpyenvactivateActivatevirtualenvironmentcommandsListallavailablepyenvcommandsdeactivateDeactivatevirtualenvironmentdoctorVerifypyenvinstallationanddevelopmenttoolstobuildpythons.execRunanexecutablewiththeselectedPythonversionglobalSetorshowtheglobalPythonversionhelpDisplayhelpforacommandhooksListhookscriptsforagivenpyenvcommandinitConfiguretheshellenvironmentforpyenvinstallInstallaPythonversionusingpython-buildlocalSetorshowthelocalapplication-specificPythonversionprefixDisplayprefixforaPythonversionrehashRehashpyenvshims(runthisafterinstallingexecutables)rootDisplaytherootdirectorywhereversionsandshimsarekeptshellSetorshowtheshell-specificPythonversionshimsListexistingpyenvshimsuninstallUninstallaspecificPythonversionversionShowthecurrentPythonversionanditsoriginversion-fileDetectthefilethatsetsthecurrentpyenvversionversion-nameShowthecurrentPythonversionversion-originExplainhowthecurrentPythonversionissetversionsListallPythonversionsavailabletopyenvvirtualenvCreateaPythonvirtualenvusingthepyenv-virtualenvpluginvirtualenv-deleteUninstallaspecificPythonvirtualenvvirtualenv-initConfiguretheshellenvironmentforpyenv-virtualenvvirtualenv-prefixDisplayreal_prefixforaPythonvirtualenvversionvirtualenvsListallPythonvirtualenvsfoundin`$PYENV_ROOT/versions/*'.whenceListallPythonversionsthatcontainthegivenexecutablewhichDisplaythefullpathtoanexecutable
二、使用pipenv
1. 简介
pipenv是用来替换pip+virtualenv的解决方案。
官网:https://github.com/pypa/pipenv
2. 安装
#更新一下pip,并且安装下pipenv/home/kyan/.pyenv/shims/pipinstall--upgradepip/home/kyan/.pyenv/shims/pipinstallpipenv
3. 使用
mkdirpipenv_testcdpipenv_test#项目使用python3.8.0pyenvshell3.8.0pipenvinstall--python=`pyenvwhichpython`#Creatingavirtualenvforthisproject...pipenvinstall#安装需要的软件包pipenvinstallrequests#卸载pipenvuninstallrequests#检查包pipenvcheck#全部卸载pipenvuninstall--all#展示所有依赖图pipenvgraph#使用当前环境执行命令pipenvrunpython--version#进入shell环境pipenvshell
感谢你能够认真阅读完这篇文章,希望小编分享如何搭建Python生产环境pyenv和pipenv内容对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。