Ubuntu编译安装Python(jupyter升级)

你可能会问为什么要编译安装Python?apt它不香么?
apt确实香,但如果你是Ubuntu 18.04,用apt安装Python3.8,你会发现

>>> apt install python3.8
>>> python3.8 --version
Pyhton 3.8.0

你没看错,是3.8.0,而目前已经出到3.8.7了。也许你可以添加ppa来安装3.8.7,但那个不是官方的版本。这时就需要编译安装大法了

下载源码

>>> wget https://www.python.org/ftp/python/3.8.7/Python-3.8.7.tgz
# 如果以上的地址速度极其慢,可以尝试使用国内的镜像地址
>>> wget https://npm.taobao.org/mirrors/python/3.8.7/Python-3.8.7.tgz
# 解压
>>> tar -xzvf Python-3.8.7.tgz

安装

# 创建安装目录
>>> mkdir /usr/python3
>>> cd Python-3.8.7
>>> ./configure --enable-optimizations --prefix=/usr/python3
>>> make && make install
>>> cd /usr/python3/bin
>>> ./python3 --version
Python 3.8.7

修改Python3、pip3

>>> update-alternatives --install /usr/bin/python3 python3 /usr/python3/bin/python3.8 2
>>> update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1

pip不需要手动设置,系统会自动调整为/usr/python3/bin/pip

重新安装包

# 导出python3.6下的包列表
>>> pip freeze > requirements.txt
# 安装列表中的包
>>> pip install -r requirements.txt

如果存在版本问题,可将版本限制去掉,安装最新版本即可

通过上面操作,成功将jupyterhub+jupyterlab迁移至Python3.8下,而没有影响之前的配置
jupyterhub+jupyterlab配置参考:https://blog.csdn.net/MacwinWin/article/details/103858681
Ubuntu编译安装Python(jupyter升级)_第1张图片
参考:
https://dev.to/serhatteker/how-to-upgrade-to-python-3-7-on-ubuntu-18-04-18-10-5hab
https://blog.csdn.net/xietansheng/article/details/84791703

你可能感兴趣的:(Python,工具,Ubuntu,python,jupyterhub,jupyterlab,jupyter)