一、python了解
1、python
python是一种面向对象的编程语言,
2、python的优点
简单、优雅、明确
强大的第三方库模块
可跨平台移植
3、python的缺点
代码执行速度慢,相比C语言,不过现在python的
异步并发框架导致执行速度慢
python是开源的编程语言,代码不能加密
二、python的安装
1、官网安装
python安装官网为:www.python.org
2、linux镜像自带安装
可直接通过yum命令安装
[kiosk@oundation51 Desktop]$ yum install python
3、安装包安装
1.下载python3.6安装包到本地
2.解压安装包到/opt/目录
[kiosk@oundation51 Desktop]$ xf Python-3.6.4.tgz -C /opt/
[kiosk@oundation51 Desktop]$ cd /opt/
[kiosk@oundation51 Desktop]$ ls
Python-3.6.4 rh
[kiosk@oundation51 Desktop]$ cd Python-3.6.4/
[kiosk@oundation51 Desktop]$ ls
aclocal.m4 Doc LICENSE Objects pyconfig.h.in
config.guess Grammar Mac Parser Python
config.sub Include Makefile.pre.in PC README.rst
configure install-sh Misc PCbuild setup.py
configure.ac Lib Modules Programs Tools
3.编译
注意: 先切换到/opt/Python-3.6.4
[kiosk@oundation51 Python-3.6.4]$ ./configure --prefix=/usr/local/python3 #### 编译到指定目录
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.6... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux
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 `/opt/Python-3.6.4':
configure: error: no acceptable C compiler found in $PATH #### 报错,提示没有c编译器
See `config.log' for more details
4.安装gcc
-安装gcc(C语言的编译器),因为python解释器是C语言编写的;
[kiosk@oundation51 Python-3.6.4]$ install gcc -y
5.安装gcc后重新编译
[kiosk@oundation51 Python-3.6.4]$ ./configure --prefix=/usr/local/python3
4、检测并安装
[kiosk@oundation51 Python-3.6.4]$ make && make install #### 检测安装时会提示报错
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1 #### 没有 zlib 开发包
5、安装zlib开发包
[kiosk@oundation51 Python-3.6.4]$ yum search zlib
Loaded plugins: langpacks
============================== N/S matched: zlib ==============================
perl-Compress-Raw-Zlib.x86_64 : Low-level interface to the zlib compression
: library
perl-IO-Zlib.noarch : Perl IO:: style interface to Compress::Zlib
zlib-devel.i686 : Header files and libraries for Zlib development
zlib-devel.x86_64 : Header files and libraries for Zlib development
zlib.x86_64 : The compression and decompression library
zlib.i686 : The compression and decompression library
Name and summary matches only, use "search all" for everything.
[kiosk@oundation51 Python-3.6.4]$ yum install zlib-devel.x86_64 -y
开发包安装完成后,重新检测安装!!
[kiosk@oundation51 Python-3.6.4]$ make && make install
6.软连接的创建
[kiosk@oundation51 Python-3.6.4]$ ln -s /usr/local/python3/bin/python3 /usr/bin/python3
7.检测是否成功?
创建成功后可像命令一样使用python
[kiosk@oundation51 Python-3.6.4]$ python3
Python 3.6.4 (default, May 29 2018, 21:53:47)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
三、python的编码格式
ASCII:1字节=8bit,2**8-1=255
Unicode:2字节=16bit,2**16-1=65535
utf-8:可变字节编码,英文:1字节,中文3字节
1、python3
[kiosk@oundation51 mnt]$ vim hello.py
[kiosk@oundation51 mnt]$ chmod +x hello.py
[kiosk@oundation51 mnt]$ ./hello.py
hello world!!
[kiosk@oundation51 mnt]$ cat hello.py
#!/usr/bin/python3
print("hello world!!")
2、python2.7
python2中需要加入编码格式
[kiosk@oundation51 mnt]# chmod +x hello1.py
[kiosk@oundation51 mnt]]# ./hello1.py
File "./hello1.py", line 3
SyntaxError: Non-ASCII character '\xe4' in file ./hello1.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
[kiosk@oundation51 mnt]# cat hello1.py
#!/usr/bin/python
print("hello world")
print("westos")
[kiosk@oundation51 mnt]# vim hello1.py
[kiosk@oundation51 mnt]# ./hello1.py
hello world
westos
3、ipython自动补齐安装包
1.下载ipython安装包
2.将安装包中的rmp包全部安装
[kiosk@oundation51 ipython]$ yum install * -y
进入ipython模式,会有自动补齐功能
[kiosk@oundation51 Desktop]$ ipython
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
Type "copyright", "credits" or "license" for more information.
IPython 3.2.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: pr
%%prun %precision %profile %prun print property
KeyboardInterrupt
四、pycharm软件安装
1.下载pycharm安装包
2.解压安装
[kiosk@oundation51 ~]$ tar xf pycharm-community-2017.1.4.tar.gz -C /opt/
[kiosk@oundation51 ~]$ cd /opt/
[kiosk@oundation51 opt]$ ls
pycharm-community-2017.1.4 Python-3.6.4 rh
[kiosk@oundation51 opt]$ mv pycharm-community-2017.1.4 pycharm
[kiosk@oundation51 opt]$ cd pycharm/
[kiosk@oundation51 pycharm]# ls
bin help Install-Linux-tar.txt lib plugins
build.txt helpers jre64 license
[kiosk@oundation51 pycharm]# cd bin/
[kiosk@oundation51 bin]# ls
format.sh idea.properties pycharm64.vmoptions restart.py
fsnotifier inspect.sh pycharm.png
fsnotifier64 log.xml pycharm.sh
fsnotifier-arm printenv.py pycharm.vmoptions
[kiosk@oundation51 bin]# su - student ### 安装时切换普通用户
Last login: Thu May 11 20:23:54 EDT 2017 on pts/0
[kiosk@oundation51 ~]$ cd /opt/pycharm/bin/
[kiosk@oundation51 bin]$ ./pycharm.sh
首次安装选择默认安装就ok
3、pycharm快捷设置
Alt + Insert:新建文件/目录
ctrl + alt + s:python配置
ctrl + shift + F10:执行
ctrl + d :快速复制
ctrl + alt + l :调整格式