Ubuntu上安装和使用Python3.6的方法是什么

62次阅读
没有评论

共计 3019 个字符,预计需要花费 8 分钟才能阅读完成。

这篇文章主要介绍了 Ubuntu 上安装和使用 Python3.6 的方法是什么的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇 Ubuntu 上安装和使用 Python3.6 的方法是什么文章都会有所收获,下面我们一起来看看吧。

错误如下:

david@KingChef-Workstation:~/learnpy$ python3 ex5.pyFile  ex5.py , line 9print(f Let s talk about {my_name}. )^SyntaxError: invalid syntax

再三检查发现代码没有问题,但运行就是出错。听说 Python 各版本之间会有差异,会不会是因为 Python 版本本身的问题呢?

david@KingChef-Workstation:~$ python -VPython 2.7.12david@KingChef-Workstation:~$ python3 -VPython 3.5.2

Ubuntu 16.04 默认安装的 Python 版本是 2.7 和 3.5,而  Learn Python 3 The Hard Way  里面用的是 Python 3.6。需要安装 Python 3.6 了,好在 Ubuntu 下面可以很方便的让多个 Python 版本同时存在,只要在运行的时候指定 Python 的版本号就可以了。要在 Ubuntu 16.04 上面安装 Python 3.6 需要添加 python 3.6 的源:

david@KingChef-Workstation:~$ sudo add-apt-repository ppa:jonathonf/python-3.6[sudo] password for david: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.6Press [ENTER] to continue or ctrl-c to cancel adding it

这里提示我们安装 Python 3.6 后不要删除 Python 3.5,不然的话系统会崩溃,因为 Linux 系统里面对 Pyhon 的依赖是比较多的,网上能查到很多人吐槽自己删除系统默认的 Python 版本后出现问题,不得不重新装回原来的版本,甚至重装系统的经历。我们根据提示键入 Enter 后,把 Python 3.6 的 PPA 源正式加入到源列表:

gpg: keyring `/tmp/tmpsnw0vrl9/secring.gpg  created
gpg: keyring `/tmp/tmpsnw0vrl9/pubring.gpg  created
gpg: requesting key F06FC659 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpsnw0vrl9/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 update 更新资源列表,然后安装 Python 3.6:

$ sudo apt update$ sudo apt install python3.6Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following additional packages will be installed:libpython3.6-minimal libpython3.6-stdlib python3.6-minimalSuggested packages:python3.6-venv python3.6-docThe following NEW packages will be installed:libpython3.6-minimal libpython3.6-stdlib python3.6 python3.6-minimal0 upgraded, 4 newly installed, 0 to remove and 1 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]

因为源文件在国外,下载软件的过程可能会超时,如果出错,可以重新运行安装命令直到安装完成。完成后可以通过查看 Python 版本来确认是否能够安装成功:

$ python -VPython 2.7.12$ python3 -VPython 3.5.2$ python3.5 -VPython 3.5.2$ python3.6 -VPython 3.6.5

几个命令下来我们看到,默认的版本还是 2.7,Python3 的默认版本还是 3.5.2,如果要用 Python 3.6 运行.py 脚本的话,需要直接指定 Python 版本:

~/learnpy$ python3 ex5.pyFile  ex5.py , line 9print(f Let s talk about {my_name}. )^SyntaxError: invalid syntax~/learnpy$ python3.6 ex5.pyLet s talk about David Wei.He s 170cm tall.He s 68kg heavy.Actually that s not too heavy.He s got Black eyes and Black hair.His teeth are usually White depending on the coffee.If I add 36, 170, and 68 I get 274.

python 主要应用领域有哪些

1、云计算,典型应用 OpenStack。

2、WEB 前端开发,众多大型网站均为 Python 开发。

3、人工智能应用,基于大数据分析和深度学习而发展出来的人工智能本质上已经无法离开 python。

4、系统运维工程项目,自动化运维的标配就是 python+Django/flask。

5、金融理财分析,量化交易,金融分析。

6、大数据分析。

关于“Ubuntu 上安装和使用 Python3.6 的方法是什么”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Ubuntu 上安装和使用 Python3.6 的方法是什么”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-13发表,共计3019字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)