赞
踩
系统:Ubuntu18.04,安装Python版本Python3.7
step1:下载想要的Python版本,本次安装的版本为Python-3.7.0,下载网址:https://www.python.org/downloads/source/
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 system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.7... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/python/Python-3.7.0':
configure: error: no acceptable C compiler found in $PATH
See `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 http://python.org/dev/peps/pep-0263/ for details
需要在开头加入 # -*- coding: utf-8 -*
再次运行python hello.py 成功运行~
lee@lee-Aspire-VN7-592G:~/文档/python$ python hello.py
hello world
真心感觉安装Python其实挺费劲的,不过装完以后感觉还是挺好的,大家如果有问题可以留言,有错误也欢迎指出~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。