资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

如何搭建Python生产环境pyenv和pipenv

这篇文章主要介绍了如何搭建Python生产环境pyenv和pipenv,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

10多年的固始网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整固始建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“固始网站设计”,“固始网站推广”以来,每个客户项目都认真落实执行。

基于debian:

$ cat /proc/version
Linux version 4.19.0-6-amd64 (debian-kernel@lists.debian.org) (gcc version 8.3.0 (Debian 8.3.0-6)) #1 SMP Debian 
4.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

curl https://pyenv.run | bash
# 按照提示,将下面三行添加到~/.bashrc文件中
# Load pyenv automatically by adding
# the following to ~/.bashrc:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="/home/kyan/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# 重启shell环境
exec $SHELL
# 更新
pyenv update
# 卸载,还需要删除添加到bashrc文件中的那几行
rm -fr ~/.pyenv

4. 安装和删除指定的python版本

# 安装
# 在安装python之前,最好安装下面的包,不然会有 "Missing ctypes" 错误
sudo apt-get install libffi-dev
sudo apt-get install libbz2-dev
sudo apt-get install libreadline-dev
sudo apt-get install libsqlite3-dev
pyenv install 3.8.0
# 删除
pyenv uninstall 3.8.0
# 详细命令参数,可以参考help
kyan@kyanvultrtokyo0:~$ pyenv 
pyenv 1.2.15
Usage: pyenv  []
Some useful pyenv commands are:
   commands    List all available pyenv commands
   --version   Display the version of pyenv
   activate    Activate virtual environment
   commands    List all available pyenv commands
   deactivate   Deactivate virtual environment
   doctor      Verify pyenv installation and development tools to build pythons.
   exec        Run an executable with the selected Python version
   global      Set or show the global Python version
   help        Display help for a command
   hooks       List hook scripts for a given pyenv command
   init        Configure the shell environment for pyenv
   install     Install a Python version using python-build
   local       Set or show the local application-specific Python version
   prefix      Display prefix for a Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   root        Display the root directory where versions and shims are kept
   shell       Set or show the shell-specific Python version
   shims       List existing pyenv shims
   uninstall   Uninstall a specific Python version
   version     Show the current Python version and its origin
   version-file   Detect the file that sets the current pyenv version
   version-name   Show the current Python version
   version-origin   Explain how the current Python version is set
   versions    List all Python versions available to pyenv
   virtualenv   Create a Python virtualenv using the pyenv-virtualenv plugin
   virtualenv-delete   Uninstall a specific Python virtualenv
   virtualenv-init   Configure the shell environment for pyenv-virtualenv
   virtualenv-prefix   Display real_prefix for a Python virtualenv version
   virtualenvs   List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
   whence      List all Python versions that contain the given executable
   which       Display the full path to an executable

二、使用pipenv

1. 简介

pipenv是用来替换pip+virtualenv的解决方案。

官网:https://github.com/pypa/pipenv

2. 安装

# 更新一下pip,并且安装下pipenv
/home/kyan/.pyenv/shims/pip install --upgrade pip
/home/kyan/.pyenv/shims/pip install pipenv

3. 使用

mkdir pipenv_test
cd pipenv_test
# 项目使用python 3.8.0
pyenv shell 3.8.0
pipenv install --python=`pyenv which python`
# Creating a virtualenv for this project...
pipenv install
# 安装需要的软件包
pipenv install requests
# 卸载
pipenv uninstall requests
# 检查包
pipenv check
# 全部卸载
pipenv uninstall --all
# 展示所有依赖图
pipenv graph
# 使用当前环境执行命令
pipenv run python --version
# 进入shell环境
pipenv shell

感谢你能够认真阅读完这篇文章,希望小编分享如何搭建Python生产环境pyenv和pipenv内容对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,遇到问题就找创新互联,详细的解决方法等着你来学习!


新闻名称:如何搭建Python生产环境pyenv和pipenv
当前URL:http://cdkjz.cn/article/gcdgsh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220