专注做网管的电脑公司
  • 微信公众号
  • 联系我们
  • 客服热线:13726442969
  • python Linux 环境 (版本隔离工具)

    2020-08-24 09:33:02 381

      • 1、安装pyenv


         
        GitHub官网:
     
        https://github.com/pyenv/pyenv-installer/blob/master/README.rst
     
    Install:
    $ curl https://pyenv.run | bash
    pyenv.run redirects to the install script in this repository and the invocation above is equivalent to:
    Restart your shell so the path changes take effect:
    You can now begin using pyenv.
    Update:
    $ pyenv update
    Uninstall: pyenv is installed within $PYENV_ROOT (default: ~/.pyenv). To uninstall, just remove it:
    $ rm -fr ~/.pyenv
    and remove these three lines from .bashrc:
    export PATH="$HOME/.pyenv/bin:$PATH"eval "$(pyenv init -)"eval "$(pyenv virtualenv-init -)"
    If you need, export USE_GIT_URI to use git:// instead of https:// for git clone.

      • 2、安装python


     
        查看python可用版本
     
       
    [python@zhangyi-centos7 ~]$ pyenv install -l
     
     
      
        

        2.1 在线安装

     
    爱土壤电脑

     

     

    2.2如网络环境不好


     

     
    到官网下载 对应版本源码 https://www.python.org/downloads/source/
    两个包都下载好
    Python-x.x.x.tar.xz
    Python-x.x.x.tgz
    放入用户目录下的.pyenv/cache
    makedir -r ~/.pyenv/cache

     

     
     

    3、3.7版本依赖问题:


     

     
    3.7版本需要一个新的包libffi-devel,安装此包之后再次进行编译安装即可。
     
    #yum install libffi-devel -y
    若在安装前移除了/usr/bin下python的文件链接依赖,此时yum无法正常使用,需要自己下载相关软件包安装,为节省读者时间,放上链接
     
    #rpm -ivh libffi-devel-3.0.13-18.el7.x86_64.rpm
    安装完成后重新进行make install,结束后再次配置相关文件的软连接即可。
     

    4、使用 pyenv 进行版本隔离


     
     

    查看已安装的python版本

     
     
     

    5、把用户目录下的环境设置成新安装的python版本


     
     
    pyenv local 3.7.4

     

     

    6、增加虚拟环境


     
    pyenv virtualenv zhangyi
     
     
    查看虚拟环境
     
     
     
     

    7、安装ipython


     
    切换pip源
     
    Linux系统:
     
    复制代码
    mkdir ~/.pip 
    cat > ~/.pip/pip.conf << EOF
     
    [global]
    trusted-host=mirrors.aliyun.com
    index-url=https://mirrors.aliyun.com/pypi/simple/ EOF
     
    pip install ipython
    复制代码

     

     
     

    8、安装jupyter


      
    pip install jupyter

     

     
    启动jupyter初始化密码
    jupyter notebook passwd

     

     
    指定jupyter 启动绑定的ip 
     
    jupyter notebook --ip=0.0.0.0

     

     
     
    浏览器访问jupyter
     
     
     
     
     

    9、Python 虚拟环境包导出/导入


     
    导出
     
    pip freeze > requirement

     

     
    导入
     
    pip -r requirement

     

    这里不做演示了