How to install Python in Ubuntu 在Ubuntu编译安装Python

2021年5月27日 355点热度 0人点赞 0条评论

How to install Python in Ubuntu

This is an old school topic. You may be professional in Python, Java, C++, and Rust. You may use conda in your research. But what about commercial use? Conda is not free. Sometimes you need a pure Python environment, especially when you are using Docker to build an image.

本文将介绍如何在ubuntu18.04系统编译安装Python。不使用apt-get或者conda.

假设你已经是root user. 首先,安装必要的依赖

apt-get update && apt-get upgrade -y &&\
    apt-get install -y wget \
    build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev

下载并编译Python 3.8.0

wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz &&\
    tar -xf Python-3.8.0.tgz &&\
    cd Python-3.8.0 &&\
    ./configure --enable-optimizations &&\
    make -j8 &&\
    make altinstall

设置这个Python3.8为默认的Python3,pip3.8为默认的pip3

update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.8 3 &&\
    update-alternatives --install /usr/bin/pip3 pip3 /usr/local/bin/pip3.8 3 &&\
    pip3 install --upgrade pip

Dong Wang

A final year master's student in computer science at Uppsala University in Sweden. I am interested in deep learning, computer vision, and optimization. I am actively looking for Ph.D. position.

文章评论