温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2022-11-22 10:29:50 来源:亿速云 阅读:118 作者:iii 栏目:服务器

这篇文章主要介绍了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的方法是什么”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI