如果你的服务器无法访问GitHub,那么也会像我一样产生如下的问题:
[python@localhost ~]$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 1839 100 1839 0 0 41 0 0:00:44 0:00:44 --:--:-- 438
Cloning into '/home/python/.pyenv'...
fatal: unable to access 'https://github.com/pyenv/pyenv.git/': TCP connection reset by peer
Failed to git clone https://github.com/pyenv/pyenv.git
那么可以试一下我的解决方案
1.首先安装依赖:
[root@localhost ~]# yum install lbzip2 openssl-devel readline-devel bzip2-libs gcc sqlite-devel bzip2-devel openssl-libs zlib -y
2.然后安装git 因为之后还是需要这个进行安装:
[root@localhost ~]# yum install git -y
3.创建用户python,然后为其用户设置密码为123456,代码及结果如下:
[root@localhost ~]# useradd python
[root@localhost ~]# echo '123456' | passwd python --stdin
Changing password for user python.
passwd: all authentication tokens updated successfully.
4.切换到用户python
[root@localhost ~]# su - python
5.然后进行安装pyenv, 如下命令为官网的安装方式
[python@localhost ~]$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
如果你的网络可以访问GitHub并且安装成功,那么可以跳过此步骤,若遇到上面我的那种情况,可以采取如下措施,此措施是我亲自实践,亲测有效:
5. 1)首先在本地创建文件installer.sh
[python@localhost ~]$ touch installer.sh
2) 查看文件信息:
[python@localhost ~]$ ll
total 0
-rw-rw-r-- 1 python python 0 Aug 26 11:27 installer.sh
3)若代码权限不足,请添加权限,如下(注意是以root权限添加):
[root@localhost python]# chmod 777 installer.sh
[root@localhost python]# ll
total 0
-rwxrwxrwx 1 python python 0 Aug 26 11:27 installer.sh
4)切回python用户,然后打开installer.sh:
[python@localhost ~]$ vi installer.sh
5)复制以下内容进文件:
#!/usr/bin/env bash
set -e
[ -n "$PYENV_DEBUG" ] && set -x
if [ -z "$PYENV_ROOT" ]; then
export PYENV_ROOT="${HOME}/.pyenv"
fi
colorize() {
if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
else echo -n "$2"
fi
}
# Checks for `.pyenv` file, and suggests to remove it for installing
if [ -d "${PYENV_ROOT}" ]; then
{ echo
colorize 1 "WARNING"
echo ": Can not proceed with installation. Kindly remove the '${PYENV_ROOT}' directory first."
echo
} >&2
exit 1
fi
failed_checkout() {
echo "Failed to git clone $1"
exit -1
}
checkout() {
[ -d "$2" ] || git -c advice.detachedHead=0 clone --branch "$3" --depth 1 "$1" "$2" || failed_checkout "$1"
}
if ! command -v git 1>/dev/null 2>&1; then
echo "pyenv: Git is not installed, can't continue." >&2
exit 1
fi
if [ -n "${USE_GIT_URI}" ]; then
GITHUB="git://github.com"
else
GITHUB="https://github.91chi.fun//https://github.com"
fi
checkout "${GITHUB}/pyenv/pyenv.git" "${PYENV_ROOT}" "${PYENV_GIT_TAG:-master}"
checkout "${GITHUB}/pyenv/pyenv-doctor.git" "${PYENV_ROOT}/plugins/pyenv-doctor" "master"
checkout "${GITHUB}/pyenv/pyenv-installer.git" "${PYENV_ROOT}/plugins/pyenv-installer" "master"
checkout "${GITHUB}/pyenv/pyenv-update.git" "${PYENV_ROOT}/plugins/pyenv-update" "master"
checkout "${GITHUB}/pyenv/pyenv-virtualenv.git" "${PYENV_ROOT}/plugins/pyenv-virtualenv" "master"
checkout "${GITHUB}/pyenv/pyenv-which-ext.git" "${PYENV_ROOT}/plugins/pyenv-which-ext" "master"
if ! command -v pyenv 1>/dev/null; then
{ echo
colorize 1 "WARNING"
echo ": seems you still have not added 'pyenv' to the load path."
echo
} >&2
{ # Without args, `init` commands print installation help
"${PYENV_ROOT}/bin/pyenv" init || true
"${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
} >&2
fi
6)运行该文件:
[python@localhost ~]$ bash installer.sh
以下为代码执行结果
Cloning into '/home/python/.pyenv'...
remote: Enumerating objects: 992, done.
remote: Counting objects: 100% (992/992), done.
remote: Compressing objects: 100% (427/427), done.
remote: Total 992 (delta 576), reused 708 (delta 438), pack-reused 0
Receiving objects: 100% (992/992), 489.66 KiB | 76.00 KiB/s, done.
Resolving deltas: 100% (576/576), done.
Cloning into '/home/python/.pyenv/plugins/pyenv-doctor'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 1), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (11/11), done.
Cloning into '/home/python/.pyenv/plugins/pyenv-installer'...
remote: Enumerating objects: 16, done.
remote: Counting objects: 100% (16/16), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 16 (delta 1), reused 7 (delta 0), pack-reused 0
Unpacking objects: 100% (16/16), done.
Cloning into '/home/python/.pyenv/plugins/pyenv-update'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
Cloning into '/home/python/.pyenv/plugins/pyenv-virtualenv'...
remote: Enumerating objects: 61, done.
remote: Counting objects: 100% (61/61), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 61 (delta 11), reused 27 (delta 1), pack-reused 0
Unpacking objects: 100% (61/61), done.
Cloning into '/home/python/.pyenv/plugins/pyenv-which-ext'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
WARNING: seems you still have not added 'pyenv' to the load path.
# Load pyenv automatically by appending
# the following to
~/.bash_profile if it exists, otherwise ~/.profile (for login shells)
and ~/.bashrc (for interactive shells) :
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Restart your shell for the changes to take effect.
# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:
eval "$(pyenv virtualenv-init -)"
然后依照提示复制以下内容进 .bash_profile
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
7)编辑该文件:
[python@localhost ~]$ vi ~/.bash_profile
内容修改如下:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
~
8)保存退出
6.然后退出当前用户 ,然后再进去,目的是刷新一下shell, 当然不反对直接重新连接登录
[python@localhost ~]$ exit
logout
[root@localhost python]# su - python
7.然后运行以下代码可以证明pyenv安装完成:
[python@localhost ~]$ pyenv versions
system (set by /home/python/.pyenv/version)
上面那个不是官方文件,我改了里面的链接,我是通过改到加速镜像来模仿官方进行下载的
如果下载失败的话可以联系我