欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ubuntu16.04 nvidia-docker下安装python3.6 和 pip

程序员文章站 2022-05-01 15:56:26
...

执行apt-get install python3.6 失败

Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package python3.6
E: Couldn’t find any package by glob ‘python3.6’
E: Couldn’t find any package by regex ‘python3.6’

1.添加ppa到系统

add-apt-repository ppa:jonathonf/python-3.6

成功显示

A plain backport of just Python 3.6. System extensions/Python libraries may or may not work.
Don’t remove Python 3.5 from your system - it will break.
More info: https://launchpad.net/~jonathonf/+archive/ubuntu/python-3.6
Press [ENTER] to continue or ctrl-c to cancel adding it # 按enter键进入下一步
Error: retrieving gpg key timed out.
gpg: keyring /tmp/tmp9q8igw_p/secring.gpg' created gpg: keyring/tmp/tmp9q8igw_p/pubring.gpg’ created
gpg: requesting key F06FC659 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp9q8igw_p/trustdb.gpg: trustdb created
gpg: key F06FC659: public key “Launchpad PPA for J Fernyhough” imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
OK

2.更新

apt-get update

3.安装

apt-get install python3.6

安装成功

修改python命令指向

1.首先查看命令指向

ls -l /usr/bin | grep python

Ubuntu16.04 nvidia-docker下安装python3.6 和 pippython指令默认指向2.7版本

2.删除原软链接

rm /usr/bin/python

3.建立python到python3.6新的软链接

ln -s /usr/bin/python3.6 /usr/bin/python 

成功建立新链接

安装pip

1.使用apt-get install python3-pip安装失败

指向是python3.5 下的pip

输入 pip --version
显示 pip 19.1.1 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)

2.换个方式安装pip

1.先将指向python3的命令也链接为python3.6

update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
update-alternatives --config python3

成功更改!

2.继续装pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall

完成安装pip:

pip 19.1.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

接下来就可以用pip安装numpy,scipy,pandas 等。

注:参考文章:

  1. Docker下的ubuntu (阿里云服务器)安装python3.6 及pip3
  2. 记Ubuntu升级python3.6和pip3升级后出错
  3. Ubuntu16.04安装Python3.6 和pip(python3 各版本切换)