windows - 在 Windows 上的 Ubuntu 上的 Bash 上升级 python 版本?

标签 windows bash ubuntu

所以我目前正在尝试升级 Windows 子系统上 ubuntu 上的 bash 中的 python 版本。但是据我了解,从命令行更新 python 并不容易。最后,我的 unix 子系统到底“在哪里”?例如,我的文件系统上是否有类似 unix 的部分,我可以将文件拖入其中?谢谢

最佳答案

这是一个较老的问题,但是我今天不得不做同样的事情(在我的 Windows 10 笔记本电脑上使用 python3.6)。

Windows + R(打开运行命令对话框)
输入:bash + 按 Enter

您将获得一个新的 windows bash 提示窗口。

首先键入 lsb_release -a 以检查您是否在 Windows 机器上运行最新的 bash/ubuntu 环境(可能是 ubuntu 14.04,而 16.04 是当前版本)。

raz@HOSTNAME:~/myPlayground$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.4 LTS
Release:        16.04
Codename:       xenial

如果您通过运行 do-release-upgrade 运行旧版本升级

raz@HOSTNAME:~/myPlayground$ sudo do-release-upgrade
[sudo] password for raz:
Checking for a new Ubuntu release
No new release found.

添加PPA自定义仓库(标准apt仓库目前只有3.5个)

raz@HOSTNAME:~/myPlayground$ sudo 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

gpg: keyring `/tmp/tmp5vq72la1/secring.gpg' created
gpg: keyring `/tmp/tmp5vq72la1/pubring.gpg' created
gpg: requesting key F06FC659 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp5vq72la1/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

更新apt信息:

raz@HOSTNAME:~/myPlayground$ sudo apt-get update
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:3 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial InRelease [18.0 kB]
Get:4 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main amd64 Packages [4,760 B]
Get:5 http://ppa.launchpad.net/jonathonf/python-3.6/ubuntu xenial/main Translation-en [2,128 B]
Get:6 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Fetched 241 kB in 10s (22.2 kB/s)
Reading package lists... Done

最后安装python3.6:

raz@HOSTNAME:~/myPlayground$ sudo apt-get install python3.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
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 3 not upgraded.
Need to get 4,505 kB of archives.
After this operation, 23.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

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 4s (979 kB/s)
Selecting previously unselected package libpython3.6-minimal:amd64.
(Reading database ... 31944 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) ...
raz@HOSTNAME:~/myPlayground$

检查你的 python 版本:

raz@HOSTNAME:~/myPlayground$ python -V
Python 2.7.12
raz@HOSTNAME:~/myPlayground$ python3 -V
Python 3.5.2
raz@HOSTNAME:~/myPlayground$ python3.6 -V
Python 3.6.5

关于windows - 在 Windows 上的 Ubuntu 上的 Bash 上升级 python 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44403928/

相关文章:

windows - Chrome 使用 Windows 8 模式

c++ - 我使用什么 C/C++ 库来更改 Windows 中的 HTTP 数据包?

windows - 在 Windows 中通过 SSH 服务器的 Git,找不到共享库

linux - 通过管道 awk 进行排序无法正确排序

linux - 制作 bash 脚本以接受来自文件的输入或管道输出

android - ioctl LOOP_SET_FD 失败

python - 当从列表中获取 Python Glob 模块的参数时,文件名大小写更改为小写

bash - 一次循环遍历两个数组值

json - 使用 jq 更新 JSON 文件时缺少内容

selenium - 禁用 Firefox 更新 Ubuntu 服务器