Python第一天 安装 shell 文件

时间:2023-03-09 22:05:54
Python第一天  安装 shell  文件

Python第一天  安装  shell  文件

python里面一切都是对象 object

代码缩进:建议用四个空格来缩进,不要用tab键

安装

Linux自带python,windows需要下载msi文件进行安装,还要指定环境变量

#查看python版本和当前安装的python版本
python -V

rpm -qa|grep python
python-2.6.6-52.el6.x86_64


python shell
解释器交互
python shell
ipython(需要安装第三方模块ipython包)

python软件包安装方式,pip,pip能解决模块依赖关系
pip网上搜索位置
https://pypi.python.org/pypi/

安装pip软件包
先安装epel源
yum install -y epel-release
yum makecache
yum install -y python-pip

列出python包
pip list
安装python包
pip install ipython
指定版本号
pip install ipython==1.2.1

第三方python模块安装包路径
/usr/lib/python2.6/site-packages/
/usr/lib64/python2.6/site-packages/

[root@gz3 ~]# ipython
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
Type "copyright", "credits" or "license" for more information.

IPython 1.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]:


python文件

执行

bash文件
vi 1.sh
#!/bin/bash
echo 'hello'

sh 1.sh
chmod +x 1.sh
./1.sh

python文件
vi 1.py
#!/usr/bin/python
print 'hello'

python 1.py
chmod +x 1.py
./1.py

python文件类型
(1)py
python源码文件
(2)pyc
Python源码文件经编译后生成的扩展名为”pyc”的文件
编译方法:
import py_compile
py_compile.compile('python源码文件绝对或相对路径')
(3)pyo
优化代码
也是经过编译的,但是优化过的源码文件,扩展名为”pyo”
python –O –m py_compile hello.py