最新公告
  • 欢迎您光临起源地模板网,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!立即加入钻石VIP
  • Python生产环境的构建(pyenv、pipenv)

    正文概述    2020-10-26   363

    Python生产环境的构建(pyenv、pipenv)

    以下文档,基于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 <command> [<args>]
    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学习网,免费的在线学习python平台,欢迎关注!

    本文转自:https://www.jianshu.com/p/d6448b0fd12f


    起源地下载网 » Python生产环境的构建(pyenv、pipenv)

    常见问题FAQ

    免费下载或者VIP会员专享资源能否直接商用?
    本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
    提示下载完但解压或打开不了?
    最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议用百度网盘软件或迅雷下载。若排除这种情况,可在对应资源底部留言,或 联络我们.。
    找不到素材资源介绍文章里的示例图片?
    对于PPT,KEY,Mockups,APP,网页模版等类型的素材,文章内用于介绍的图片通常并不包含在对应可供下载素材包内。这些相关商业图片需另外购买,且本站不负责(也没有办法)找到出处。 同样地一些字体文件也是这种情况,但部分素材会在素材包内有一份字体下载链接清单。
    模板不会安装或需要功能定制以及二次开发?
    请QQ联系我们

    发表评论

    还没有评论,快来抢沙发吧!

    如需帝国cms功能定制以及二次开发请联系我们

    联系作者

    请选择支付方式

    ×
    迅虎支付宝
    迅虎微信
    支付宝当面付
    余额支付
    ×
    微信扫码支付 0 元