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

问题描述 投票:0回答:2

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

python python-3.x windows bash ubuntu
2个回答
10
投票

这是一个较旧的问题,但是我今天必须做同样的事情(在我的 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

1
投票

您可以在“开始菜单”中搜索“Bash”,然后获取可从 Ubuntu Linux(而非 Unix)中打开命令提示符的应用程序。

据我所知,您无法从 Explorer.exe 拖放到此文件中,但您可以运行一个 Linux 文件应用程序,该应用程序可以在安装了 X11 的情况下执行此操作。

最后,从 Ubuntu 命令行应用程序上的 Bash 中,您可以运行“sudo apt-get install python3”来获取 Ubuntu 的最新版本。

© www.soinside.com 2019 - 2024. All rights reserved.