从源码安装 Python3.7 [英] Installing Python3.7 from source

查看:32
本文介绍了从源码安装 Python3.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Python3.7,所以我按照这些说明安装

I need to use Python3.7, so I followed these instructions to install it

curPath=${pwd}
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
sudo tar xzf Python-3.7.9.tgz
cd Python-3.7.9
sudo ./configure --enable-optimizations
cd ${pwd}

然后我尝试运行 python -V 并得到

I then tried to run python -V and got

Command 'python3.7' not found, did you mean:

  command 'python2.7' from deb python2.7 (2.7.18-1~20.04)
  command 'python3.9' from deb python3.9 (3.9.0-5~20.04)
  command 'python3.8' from deb python3.8 (3.8.5-1~20.04.2)

Try: sudo apt install <deb name>

我也尝试运行 whereis python 并得到

Also I tried to run whereis python and got

whereis python
python: /usr/bin/python3.8 /usr/bin/python3.8-config /usr/lib/python3.8 /usr/lib/python2.7 /usr/lib/python3.9 /etc/python3.8 /usr/local/lib/python3.8 /usr/include/python3.8

推荐答案

通过这个脚本,我能够在 ubuntu 18 上安装 python3.7

With this script, I was able to install python3.7 on ubuntu 18

curPath=${pwd}
sudo apt-get update
sudo apt-get install gcc
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev wget liblzma-dev lzma
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
sudo tar xzf Python-3.7.9.tgz
cd Python-3.7.9
sudo ./configure --enable-optimizations
sudo make
sudo make altinstall
cd ${pwd}


但是您可能应该使用 pyenv 安装它,这里有一个脚本,它将在 linux 上安装 pyenv,然后安装 python 3.7.9 .这种方法发生的速度要快很多,第一次安装大约需要一个小时.


But you should probably just install it with pyenv, here's a script that will install pyenv on linux, and then install python 3.7.9 . This method happens a lot faster, the first installation takes about an hour.

sudo apt-get install gcc build-essential libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev liblzma-dev lzma

curl https://pyenv.run | bash

bashrc="${HOME}/.bashrc"
bash_profile="${HOME}/.bash_profile"
profile="${HOME}/.profile"

checkAndAppend () {
    # Checks if some text is in a file, and if it isn't, it appends that text at the end of the file
    # $1 - The text to insert into a file
    # $2 - A file to insert text into
    if ! grep -q $2 <<< "${1}" ; then 
        echo $1 >> $2
    fi 2>/dev/null
}

checkAndAppend 'export PYENV_ROOT="$HOME/.pyenv"' $profile
checkAndAppend 'export PATH="$PYENV_ROOT/bin:$PATH"' $profile
checkAndAppend 'eval "$(pyenv init --path)"' $profile
checkAndAppend 'eval "$(pyenv init -)"' $bashrc
checkAndAppend 'eval "$(pyenv virtualenv-init -)"' $bashrc
checkAndAppend 'source $HOME/.profile' $bash_profile

RED='\033[0;31m'
printf $RED'
If your $HOME/.profile sources $HOME/.bashrc, then these lines must be inserted into $HOME/.profile before that

    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init --path)"

'

source $profile
source $bashrc
source $bash_profile

pyenv install 3.7.9

这篇关于从源码安装 Python3.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆