Ubuntu18.04中安装Python3.7教程——遇到的问题以及解决⽅
法
系统:Ubuntu18.04,安装Python版本Python3.7
step1:下载想要的Python版本,本次安装的版本为Python-3.7.0,下载⽹址:
step2:解压,放在指定的⽬录当中,本次的安装⽬录为 /usr/local/python,将Python-3.7.0放在上述的⽬录当中,可以⽤cp命令复制Python-3.7.0到该⽂件夹中sudo cp -r /usr/local/Python-3.7.0 /usr/local/python
其中:/usr/local/Python-3.7.0为Python的原⽂件夹⽬录,/usr/local/python为新⽂件夹⽬录
step3:进⼊⽬录cd /usr/local/python/Python-3.7.0
运⾏configure⽂件 sudo ./configure
lee@lee-Aspire-VN7-592G:/usr/local/python/Python-3.7.0$ sudo ./configure
checking build x86_64-pc-linux-gnu
checking host x86_64-pc-linux-gnu
checking for no
checking python3
checking for -- no
checking for -- no
checking for -- no
checking for -- no
checking no
checking no
checking no
configure: error: in `/usr/local/python/Python-3.7.0':
configure: error: no acceptable C compiler found in $PATH
ubuntu怎么安装pythonSee `config.log' for more details
出现没有c编译器的错误,解决⽅法为安装gcc,具体⽅法如下:
1、运⾏以下命令才能到gcc: sudo apt-get update
2、安装gcc: sudo apt-get install gcc
step4:此时运⾏Python可以看到系统安装了默认的Python版本:python
root@lee-Aspire-VN7-592G:/usr/local/python/Python-3.7.0# python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
step5:安装我们想要的Python版本
运⾏configure⽂件: sudo ./configure
step6:运⾏下⾯的命令安装
sudo make
sudo make install
中间可能会出现ModuleNotFoundError: No module named ‘_ctypes的错误,⽤下⾯的⽅法解决:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev
重新输⼊命令: sudo make install
安装完成以后输⼊: ./python显⽰现在版本为Python3.7
lee@lee:/usr/local/python/Python-3.7.0$ ./python
Python 3.7.0 (default, Jul 8 2019, 12:52:56)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
也可以在新的终端输⼊命令python3,显⽰也是python3.7的版本:
lee@lee:~$ python3
Python 3.7.0 (default, Jul 8 2019, 12:52:56)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
到这⾥为⽌,Python3.7已经安装完毕!接下来,我们测试基本的hello world程序~
Ubuntu中没有安装默认的Python集成开发⼯具,可以安装vim编写
sudo apt install vim-gtk
安装好vim以后可以选择在终端输⼊vim打开,或者在Ubuntu的软件列表中打开,
可以使⽤上图中的vim,也可以使⽤GVim,区别在于vim⽐较像终端界⾯,GVim是⼀个有界⾯的⽐较
友好的编辑器。
写⼀个简单的hello.py 函数
接下来,运⾏hello.py⽂件,直接运⾏python hello.py会出现以下的错误:
lee@lee-Aspire-VN7-592G:~/⽂档/python$ python hello.py
File "hello.py", line 1
SyntaxError: Non-ASCII character '\xe2' in file hello.py on line 1, but no encoding declared; see /dev/peps/pep-0263/ for details
需要在开头加⼊ # -*- coding: utf-8 -*
再次运⾏python hello.py 成功运⾏~
lee@lee-Aspire-VN7-592G:~/⽂档/python$ python hello.py
hello world
真⼼感觉安装Python其实挺费劲的,不过装完以后感觉还是挺好的,⼤家如果有问题可以留⾔,有错误也欢迎指出~
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论