当前位置: 首页 > 工具软件 > pyenv > 使用案例 >

pyenv环境安装

勾喜
2023-12-01

安装步骤

  1. 安装依赖包

    首页 ·pyenv/pyenv维基 (github.com)

     yum install -y zlib-devel libffi-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
  2. 设置环境变量

     git clone https://github.com/pyenv/pyenv.git ~/.pyenv
     ​
     echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
     echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
     echo 'eval "$(pyenv init -)"' >> ~/.bashrc
     exec $SHELL -l
      
     # 安装路径
     /root/.pyenv
  3. 测试是否安装成功

     pyenv install --list

安装自己的版本

   mkdir ~/.pyenv/cache
   cd ~/.pyenv/cache
   wget https://registry.npmmirror.com/-/binary/python/3.8.5/Python-3.8.5.tar.xz # 注意以 .tar.xz结尾
   pyenv install 3.8.5 #如果还是从国外下载的,重新登陆这个服务器
   git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv # 虚拟环境下载
   
   
 # 创建虚拟环境:pyenv virtualenv 3.8.5 zcch_env
 # 激活或切换虚拟环境:pyenv activate zcch_env
 # 进行项目的同步和环境的安装(更新 pip : python -m pip install --upgrade pip )
 # 退出虚拟环境:pyenv deactivate
 # 删除虚拟环境:rm -rf ~/.pyenv/versions/zcch_env (慎重考虑)
 # 查看所有的虚拟环境信息:ll ~/.pyenv/versions/zcch_env

常见问题

  1. pyenv 没有命令virtualenv

    镜像]pyenv-virtualenv: 镜像

 cd /root/.pyenv/plugins/ 
 rm -rf pyenv-virtualenv/ #删除虚拟环境
 git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv # 重新克下载
  1. pyenv install 3.8.5 本地包的时候报错

     /home/core/.pyenv/plugins/python-build/bin/python-build: line 1464: patch: command not found
     ​
     BUILD FAILED (CoreOS 766.5.0 using python-build 20160602)
     ​
     Inspect or clean up the working tree at /tmp/python-build.20160818195434.7155
     Results logged to /tmp/python-build.20160818195434.7155.log
     ​
     Last 10 log lines:
     /tmp/python-build.20160818195434.7155 ~
     /tmp/python-build.20160818195434.7155/Python-2.7.8 /tmp/python-build.20160818195434.7155

    解决办法,使用yum下载缺失的补丁

     yum install patch

    参考:pyenv install 2.7.8 command failed · Issue #677 · pyenv/pyenv (github.com)

  2. pyenv active nginx_monitor报错

     Failed to activate virtualenv.
     ​
     Perhaps pyenv-virtualenv has not been loaded into your shell properly.
     Please restart current shell and try again.

    解决办法:

    重新登陆服务器

  3. pyenv install 时报错 ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

    解决办法:

    Home · pyenv/pyenv Wiki (github.com)

    Common build problems · pyenv/pyenv Wiki (github.com)

     # 1
     yum install gcc zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel xz-devel
     ​
     # 2 
     CPPFLAGS=-I/usr/include/openssl11 \
     LDFLAGS=-L/usr/lib64/openssl11 \
     pyenv install -v 3.10.6

  4. pyenv gitee镜像

    pyenv: pyenv 可以让你轻松地在多个版本的 Python 之间切换

  5. pyenv virtrualenv 镜像

    pyenv-virtualenv: 镜像

 类似资料: