解决pyenv安装pyhton下载安装缓慢的问题

本文介绍如何使用Pyenv工具搭建Python开发环境,包括安装Pyenv、配置环境变量、安装指定版本的Python以及验证安装过程。
部署运行你感兴趣的模型镜像
 Python开发环境之pyenv环境搭建
2016-08-10 13:38:01
标签: 开发环境  Python  pyenv
原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://lavenliu.blog.51cto.com/5060944/1836500

首先到Github上下载Pyenv相应的一键安装脚本,

1
$ curl -L https: //raw .githubusercontent.com /yyuu/pyenv-installer/master/bin/pyenv-installer  bash


安装完毕,设置环境变量,设置环境变量,可以添加到个人家目录的.bashrc或.bash_profile及系统的全
  局的/etc/profile,

1
2
3
4
5
6
# Load pyenv automatically by adding
# the following to ~/.bash_profile:
 
export  PATH= "/home/lavenliu/.pyenv/bin:$PATH"
eval  "$(pyenv init -)"
eval  "$(pyenv virtualenv-init -)"


设置完毕之后,可以在命令行进行验证,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[lavenliu@VM_113_230_centos ~]$ . ~/.bash_profile   
[lavenliu@VM_113_230_centos ~]$ pyenv 
pyenv 20160726
Usage: pyenv < command > [<args>]
 
Some useful pyenv commands are:
    commands    List all available pyenv commands
    local        Set or show the  local  application-specific Python version
    global      Set or show the global Python version
    shell       Set or show the shell-specific Python version
    install      Install a Python version using python-build
    uninstall   Uninstall a specific Python version
    rehash      Rehash pyenv shims (run this after installing executables)
    version     Show the current Python version and its origin
    versions    List all Python versions available to pyenv
    which        Display the full path to an executable
    whence      List all Python versions that contain the given executable
 
See `pyenv help < command >'  for  information on a specific  command .
For full documentation, see: https: //github .com /yyuu/pyenv #readme


 以上都没有问题。比如,安装一个3.5.2的版本Python,

1
pyenv  install  3.5.2

如果下载速度慢的话,可以事先下载之,放到~/.pyenv/cache目录即可。修改~/.pyenv/plugins/python-build/share/python-build/3.5.2文件,

1
2
3
4
5
6
7
8
9
cat  ~/.pyenv /plugins/python-build/share/python-build/3 .5.2
#require_gcc
install_package  "openssl-1.0.2g"  "https://www.openssl.org/source/openssl-1.0.2g.tar.gz#b784b1b3907ce39abf4098702dade6365522a253ad1552e267a9a0e89594aa33"  mac_openssl -- if  has_broken_mac_openssl
install_package  "readline-6.3"  "http://ftpmirror.gnu.org/readline/readline-6.3.tar.gz#56ba6071b9462f980c5a72ab0023893b65ba6debb4eeb475d7a563dc65cafd43"  standard -- if  has_broken_mac_readline
if  has_tar_xz_support;  then
   install_package  "Python-3.5.2"  "~/.pyenv/cache/Python-3.5.2.tar.gz"  ldflags_dirs standard verify_py35 ensurepip
else
   install_package  "Python-3.5.2"  "~/.pyenv/cache/Python-3.5.2.tar.gz"  ldflags_dirs standard verify_py35 ensurepip
fi


由于没有~/.pyenv/cache目录,进行手工创建,

1
mkdir  ~/.pyenv /cache


如果使用手工安装,则需要安装一些依赖,

1
# yum install -y gcc make patch gdbm-devel openssl-devel sqlite-devel zlib-devel bzip2-devel readline-devel


需要事先准备好Python-3.5.2.tar.gz的安装包,放到~/.pyenv/cache目录下。然后,在命令行直接使用pyenv install 3.5.2即可,

1
$ pyenv  install  3.5.2


安装完毕,使用version命令进行查看,

1
2
pyenv version
3.5.2 ( set  by  /home/lavenliu/ .python-version)

至此,已经安装完毕。

本文出自 “固态U盘” 博客,请务必保留此出处http://lavenliu.blog.51cto.com/5060944/1836500

您可能感兴趣的与本文相关的镜像

Python3.9

Python3.9

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

### Python OpenCV 安装教程 #### 准备工作 为了顺利安装 OpenCV,在开始之前需确认已正确配置 Python 环境。推荐选用 Python 3.7 及以上版本,因为这些版本能更好地兼容最新的 OpenCV 库[^2]。 #### 安装方法 通过 `pip` 工具可以直接在线安装 OpenCV-Python,这是最为便捷的方式之一。对于希望减少依赖项并加快安装速度的情况,可以选择仅安装核心功能的精简版——`opencv-python-headless` 和对应的贡献模块 `opencv-contrib-python-headless`。使用国内镜像源能够显著提升下载效率: ```bash pip install opencv-python-headless --user -i https://pypi.tuna.tsinghua.edu.cn/simple pip install opencv-contrib-python-headless --user -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 如果项目确实需要用到图形界面支持,则应改为安装完整的 OpenCV 包及其扩展组件: ```bash pip install opencv-python --user -i https://pypi.tuna.tsinghua.edu.cn/simple pip install opencv-contrib-python --user -i https://pypi.tuna.tsinghua.edu.cn/simple ``` 另外,考虑到某些特定情况下可能还需要额外安装 NumPy 这样的科学计算库作为前置条件;通常来说,现代版本的 OpenCV 都已经包含了必要的依赖关系处理机制,但在遇到问题时不妨尝试手动安装 NumPy 来排除潜在冲突[^3]。 #### 版本选择 当有特殊需求指向某个具体的历史版本时,可以通过访问 PyPI 上的官方页面来获取历史发行记录,并从中挑选适合自己的版本进行离线或指定版本号安装。例如要安装 OpenCV 3.4.1.15 版本,可以在命令行执行如下指令: ```bash pip install opencv-python==3.4.1.15 ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值