首页 > 技术文章 > docker中安装python3.8

accumulationbystep 2021-12-31 10:38 原文

(1)run一个容器

命令:podman run -v /your/path/:/work/ --name="cpython" --privileged=true --dns=8.8.8.8 -p 22002:22 -it docker.io/nvidia/cuda:10.2-cudnn8-devel-ubuntu16.04

(2)安装python3.8

(2.1)让管理员开通访问外网权限

(2.2)查看系统版本信息:uname -a;cat /etc/issue;cat /proc/version

(2.3)ubuntu下,apt-get install python3.8,出现如下问题:

E: Unable to locate package python3.8-dev

E: Couldn't find any package by glob 'python3.8-dev'

E: Couldn't find any package by regex 'python3.8-dev'

解决办法:

apt-get install -y software-properties-common

add-apt-repository ppa:deadsnakes/ppa(或者add-apt-repository ppa:jonathonf/python-3.8)

apt-get update

apt-get install python3.8

 (3)设置python优先级

(3.1)查看python安装路径:which python3.8;

update-alternatives --config python

#通过update-alternatives来设置默认python版本, 最后的参数1,2是优先级,数字越大优先级越高

update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1

update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2

(4)安装pip

(4.1)wget https://bootstrap.pypa.io/get-pip.py

(4.2)出现: ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)

解决:sudo apt-get install python3.8-distutils

(4.3)python3.8 get-pip.py

  (4.4)查看版本:pip --version

(5)/usr/include/中没有python3.8版本的Python.h

安装:apt-get install python3.8-dev

推荐阅读