阿里云ECS下Ubuntu 16.04系统安装python3.6.5 环境并设置为默认

一、添加python3.6安装包并安装;

二、修改系统默认python版本为3.6;

三、安装并升级pip版本;

一、添加python3.6安装包并安装;

sudo apt-get install software-properties-common -y

二、修改系统默认python版本为3.6;

sudo add-apt-repository ppa:jonathonf/python-3.6 -y
sudo apt-get update -y
sudo apt-get install python3.6 -y
cd /usr/bin/
rm python
ln -s /usr/bin/python3.6m python

三、安装并升级pip版本;

sudo apt install python3-pip -y
pip -v
pip -V
sudo pip install --upgrade pip
pip -V
pip3 -V
[BEGIN] 2018/7/4 20:42:22
[c:\~]$ 
Connecting to 123.56.2.113:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-117-generic x86_64)
 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Welcome to Alibaba Cloud Elastic Compute Service !
root@iZxtw2roczrjdaZ:~# uname -r
4.4.0-117-generic
root@iZxtw2roczrjdaZ:~# uname -a
Linux iZxtw2roczrjdaZ 4.4.0-117-generic #141-Ubuntu SMP Tue Mar 13 11:58:07 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
root@iZxtw2roczrjdaZ:~# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.4 LTS"
root@iZxtw2roczrjdaZ:~# sudo apt-get install software-properties-common -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-87 linux-headers-4.4.0-87-generic linux-image-4.4.0-87-generic linux-image-extra-4.4.0-87-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  python3-pycurl python3-software-properties unattended-upgrades
Suggested packages:
  libcurl4-gnutls-dev python-pycurl-doc python3-pycurl-dbg bsd-mailx
The following NEW packages will be installed:
  python3-pycurl python3-software-properties software-properties-common unattended-upgrades
0 upgraded, 4 newly installed, 0 to remove and 3 not upgraded.
Need to get 104 kB of archives.
After this operation, 799 kB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu xenial/main amd64 python3-pycurl amd64 7.43.0-1ubuntu1 [42.3 kB]
Get:2 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 python3-software-properties all 0.96.20.7 [20.3 kB]
Get:3 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 software-properties-common all 0.96.20.7 [9,452 B]
Get:4 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 unattended-upgrades all 0.90ubuntu0.9 [32.3 kB]
Fetched 104 kB in 0s (1,623 kB/s)         
Preconfiguring packages ...
Selecting previously unselected package python3-pycurl.
(Reading database ... 132834 files and directories currently installed.)
Preparing to unpack .../python3-pycurl_7.43.0-1ubuntu1_amd64.deb ...
Unpacking python3-pycurl (7.43.0-1ubuntu1) ...
Selecting previously unselected package python3-software-properties.
Preparing to unpack .../python3-software-properties_0.96.20.7_all.deb ...
Unpacking python3-software-properties (0.96.20.7) ...
Selecting previously unselected package software-properties-common.
Preparing to unpack .../software-properties-common_0.96.20.7_all.deb ...
Unpacking software-properties-common (0.96.20.7) ...
Selecting previously unselected package unattended-upgrades.
Preparing to unpack .../unattended-upgrades_0.90ubuntu0.9_all.deb ...
Unpacking unattended-upgrades (0.90ubuntu0.9) ...
Processing triggers for dbus (1.10.6-1ubuntu3.3) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up python3-pycurl (7.43.0-1ubuntu1) ...
Setting up python3-software-properties (0.96.20.7) ...
Setting up software-properties-common (0.96.20.7) ...
Setting up unattended-upgrades (0.90ubuntu0.9) ...

Creating config file /etc/apt/apt.conf.d/50unattended-upgrades with new version
insserv: can not symlink(../init.d/aegis, ../rc2.d/S02aegis): File exists
insserv: can not symlink(../init.d/aegis, ../rc3.d/S02aegis): File exists
insserv: can not symlink(../init.d/aegis, ../rc4.d/S02aegis): File exists
insserv: can not symlink(../init.d/aegis, ../rc5.d/S02aegis): File exists
Synchronizing state of unattended-upgrades.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable unattended-upgrades
Processing triggers for dbus (1.10.6-1ubuntu3.3) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
root@iZxtw2roczrjdaZ:~# sudo add-apt-repository ppa:jonathonf/python-3.6 -y
gpg: keyring `/tmp/tmp1cj4_vjv/secring.gpg' created
gpg: keyring `/tmp/tmp1cj4_vjv/pubring.gpg' created
gpg: requesting key F06FC659 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp1cj4_vjv/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
root@iZxtw2roczrjdaZ:~# sudo apt-get update -y
Hit:1 http://mirrors.aliyun.com/ubuntu xenial InRelease
Get:2 http://mirrors.aliyun.com/ubuntu xenial-updates InRelease [109 kB]
Get:3 http://mirrors.aliyun.com/ubuntu xenial-security InRelease [107 kB]                     
Get:4 http://mirrors.aliyun.com/ubuntu xenial-updates/main Sources [311 kB]                    
Get:5 http://mirrors.aliyun.com/ubuntu xenial-updates/universe Sources [205 kB]                                          
Get:6 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 Packages [803 kB]             
Get:7 http://mirrors.aliyun.com/ubuntu xenial-updates/main i386 Packages [732 kB]                       
Get:8 http://mirrors.aliyun.com/ubuntu xenial-updates/main Translation-en [331 kB]                       
Get:9 http://mirrors.aliyun.com/ubuntu xenial-updates/universe amd64 Packages [640 kB]                         
Get:10 http://mirrors.aliyun.com/ubuntu xenial-updates/universe i386 Packages [584 kB]                   
Get:11 http://mirrors.aliyun.com/ubuntu xenial-updates/universe Translation-en [258 kB]
Get:12 http://mirrors.aliyun.com/ubuntu xenial-security/main Sources [126 kB]        
Get:13 http://mirrors.aliyun.com/ubuntu xenial-security/universe Sources [66.0 kB]
Get:14 http://mirrors.aliyun.com/ubuntu xenial-security/main amd64 Packages [518 kB]  
Get:15 http://mirrors.aliyun.com/ubuntu xenial-security/main i386 Packages [456 kB]  
Get:16 http://mirrors.aliyun.com/ubuntu xenial-security/main Translation-en [222 kB]  
Get:17 http://mirrors.aliyun.com/ubuntu xenial-security/universe amd64 Packages [356 kB]
Get:18 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial InRelease [18.0 kB]
Get:19 http://mirrors.aliyun.com/ubuntu xenial-security/universe i386 Packages [304 kB]
Get:20 http://mirrors.aliyun.com/ubuntu xenial-security/universe Translation-en [133 kB]    
Get:21 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main amd64 Packages [4,760 B] 
Get:22 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main i386 Packages [4,748 B]
Get:23 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main Translation-en [2,128 B]
Fetched 6,292 kB in 3s (1,707 kB/s)
Reading package lists... Done
root@iZxtw2roczrjdaZ:~# sudo apt-get install python3.6 -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-87 linux-headers-4.4.0-87-generic linux-image-4.4.0-87-generic linux-image-extra-4.4.0-87-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libpython3.6-minimal libpython3.6-stdlib python3.6-minimal
Suggested packages:
  python3.6-venv python3.6-doc binfmt-support
The following NEW packages will be installed:
  libpython3.6-minimal libpython3.6-stdlib python3.6 python3.6-minimal
0 upgraded, 4 newly installed, 0 to remove and 62 not upgraded.
Need to get 4,505 kB of archives.
After this operation, 23.1 MB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main amd64 libpython3.6-minimal amd64 3.6.5-5~16.04.york1 [574 kB]
Get:2 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main amd64 python3.6-minimal amd64 3.6.5-5~16.04.york1 [1,712 kB]
Get:3 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main amd64 libpython3.6-stdlib amd64 3.6.5-5~16.04.york1 [1,989 kB]                                                                                                
Get:4 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main amd64 python3.6 amd64 3.6.5-5~16.04.york1 [230 kB]                                                                                                            
Fetched 4,505 kB in 57s (77.9 kB/s)                                                                                                                                                                                                  
Selecting previously unselected package libpython3.6-minimal:amd64.
(Reading database ... 132892 files and directories currently installed.)
Preparing to unpack .../libpython3.6-minimal_3.6.5-5~16.04.york1_amd64.deb ...
Unpacking libpython3.6-minimal:amd64 (3.6.5-5~16.04.york1) ...
Selecting previously unselected package python3.6-minimal.
Preparing to unpack .../python3.6-minimal_3.6.5-5~16.04.york1_amd64.deb ...
Unpacking python3.6-minimal (3.6.5-5~16.04.york1) ...
Selecting previously unselected package libpython3.6-stdlib:amd64.
Preparing to unpack .../libpython3.6-stdlib_3.6.5-5~16.04.york1_amd64.deb ...
Unpacking libpython3.6-stdlib:amd64 (3.6.5-5~16.04.york1) ...
Selecting previously unselected package python3.6.
Preparing to unpack .../python3.6_3.6.5-5~16.04.york1_amd64.deb ...
Unpacking python3.6 (3.6.5-5~16.04.york1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Setting up libpython3.6-minimal:amd64 (3.6.5-5~16.04.york1) ...
Setting up python3.6-minimal (3.6.5-5~16.04.york1) ...
Setting up libpython3.6-stdlib:amd64 (3.6.5-5~16.04.york1) ...
Setting up python3.6 (3.6.5-5~16.04.york1) ...
root@iZxtw2roczrjdaZ:~# cd /usr/bin/
root@iZxtw2roczrjdaZ:/usr/bin# rm python
root@iZxtw2roczrjdaZ:/usr/bin# ln -s /usr/bin/python3.6m python
root@iZxtw2roczrjdaZ:/usr/bin# python
Python 3.6.5 (default, May  3 2018, 10:08:28) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
root@iZxtw2roczrjdaZ:/usr/bin# python2
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
root@iZxtw2roczrjdaZ:/usr/bin# sudo apt install python3-pip -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-87 linux-headers-4.4.0-87-generic linux-image-4.4.0-87-generic linux-image-extra-4.4.0-87-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libpython3-dev libpython3.5-dev python3-dev python3-setuptools python3-wheel python3.5-dev
Suggested packages:
  python-setuptools-doc
The following NEW packages will be installed:
  libpython3-dev libpython3.5-dev python3-dev python3-pip python3-setuptools python3-wheel python3.5-dev
0 upgraded, 7 newly installed, 0 to remove and 62 not upgraded.
Need to get 38.0 MB of archives.
After this operation, 55.2 MB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 libpython3.5-dev amd64 3.5.2-2ubuntu0~16.04.4 [37.3 MB]
Get:2 http://mirrors.aliyun.com/ubuntu xenial/main amd64 libpython3-dev amd64 3.5.1-3 [6,926 B]
Get:3 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 python3.5-dev amd64 3.5.2-2ubuntu0~16.04.4 [413 kB]
Get:4 http://mirrors.aliyun.com/ubuntu xenial/main amd64 python3-dev amd64 3.5.1-3 [1,186 B]
Get:5 http://mirrors.aliyun.com/ubuntu xenial-updates/universe amd64 python3-pip all 8.1.1-2ubuntu0.4 [109 kB]
Get:6 http://mirrors.aliyun.com/ubuntu xenial/main amd64 python3-setuptools all 20.7.0-1 [88.0 kB]
Get:7 http://mirrors.aliyun.com/ubuntu xenial/universe amd64 python3-wheel all 0.29.0-1 [48.1 kB]
Fetched 38.0 MB in 2s (16.0 MB/s)   

Selecting previously unselected package libpython3.5-dev:amd64.
(Reading database ... 133645 files and directories currently installed.)
Preparing to unpack .../libpython3.5-dev_3.5.2-2ubuntu0~16.04.4_amd64.deb ...
Unpacking libpython3.5-dev:amd64 (3.5.2-2ubuntu0~16.04.4) ...
Selecting previously unselected package libpython3-dev:amd64.
Preparing to unpack .../libpython3-dev_3.5.1-3_amd64.deb ...
Unpacking libpython3-dev:amd64 (3.5.1-3) ...
Selecting previously unselected package python3.5-dev.
Preparing to unpack .../python3.5-dev_3.5.2-2ubuntu0~16.04.4_amd64.deb ...
Unpacking python3.5-dev (3.5.2-2ubuntu0~16.04.4) ...
Selecting previously unselected package python3-dev.
Preparing to unpack .../python3-dev_3.5.1-3_amd64.deb ...
Unpacking python3-dev (3.5.1-3) ...
Selecting previously unselected package python3-pip.
Preparing to unpack .../python3-pip_8.1.1-2ubuntu0.4_all.deb ...
Unpacking python3-pip (8.1.1-2ubuntu0.4) ...
Selecting previously unselected package python3-setuptools.
Preparing to unpack .../python3-setuptools_20.7.0-1_all.deb ...
Unpacking python3-setuptools (20.7.0-1) ...
Selecting previously unselected package python3-wheel.
Preparing to unpack .../python3-wheel_0.29.0-1_all.deb ...
Unpacking python3-wheel (0.29.0-1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libpython3.5-dev:amd64 (3.5.2-2ubuntu0~16.04.4) ...
Setting up libpython3-dev:amd64 (3.5.1-3) ...
Setting up python3.5-dev (3.5.2-2ubuntu0~16.04.4) ...
Setting up python3-dev (3.5.1-3) ...
Setting up python3-pip (8.1.1-2ubuntu0.4) ...
Setting up python3-setuptools (20.7.0-1) ...
Setting up python3-wheel (0.29.0-1) ...

root@iZxtw2roczrjdaZ:/usr/bin# pip -v

Usage:   
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output.
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
root@iZxtw2roczrjdaZ:/usr/bin# pip -V
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.6)
root@iZxtw2roczrjdaZ:/usr/bin# sudo pip install --upgrade pip
Collecting pip
  Downloading http://mirrors.aliyun.com/pypi/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 41.9MB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-10.0.1
root@iZxtw2roczrjdaZ:/usr/bin# pip -V
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'
root@iZxtw2roczrjdaZ:/usr/bin# pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

猜你喜欢

转载自www.cnblogs.com/tqtl911/p/9265261.html