1. 程式人生 > >python 基礎1.1

python 基礎1.1

credit view 操作 pack running reference spa collected win

一.windows下安裝python 1》windows上python後綴是.msi的,下載下來後,直接雙擊運行。會在c盤生成python.exe的文件,把python.exe的文件加入到windows環境變量中:我的電腦---屬性---高級---環境變量--編輯--添加“c:\python27”--確定 C:\Python27 C:\Python27\Scripts 下載地址:https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi 2》在windows下安裝完python後,進入cmd,輸入python,也會進入python命令行 3》windows驗證python及退出
技術分享 4》windows 退出python exit() 二.linux 下安裝python 1》yum源安裝 安裝pip命令,用pip安裝ipython(pip install python) [[email protected] ~]# cd soft/ [[email protected] soft]# ls epel-release-6-8.noarch.rpm [[email protected] soft]# rpm -ivh epel-release-6-8.noarch.rpm warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%] 1:epel-release ########################################### [100%] [[email protected] soft]# cd /etc/yum.repos.d/ [[email protected] yum.repos.d]# ls //yum目錄下生成epel epel-testing.repo a bak CentOS-Base.repo epel.repo epel-testing.repo
[[email protected] yum.repos.d]# yum -y install python-pip [[email protected] yum.repos.d]# pip install ipython //安裝ipython,會通過ipython的官網,下載當前最新的版本進行安裝,註意,linux中python的版本是2.6,當前最新的iptyon的版本是6.0,網站上說明使用於python3,所以,安裝後報錯 [[email protected] yum.repos.d]# pip install ipython==1.2.1 //指定ipython的版本進行安裝, 。。。。。。 Installing collected packages: ipython Running setup.py install for ipython Successfully installed ipython-1.2.1 。。。。。。。。。。 [[email protected] yum.repos.d]# pip list //查看 You are using pip version 7.1.0, however version 9.0.1 is available. You should consider upgrading via the ‘pip install --upgrade pip‘ command. distribute (0.6.10) iniparse (0.3.1) ipython (1.2.1) pip (7.1.0) pycurl (7.19.0) Pygments (2.2.0) pygpgme (0.1) pyxdg (0.18) setuptools (0.6rc11) six (1.10.0) urlgrabber (3.9.1) yum-metadata-parser (1.1.2) [[email protected] yum.repos.d]# ipython //輸入ipython命令就會進入python下,具有補全功能 Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) 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]: 2》源碼安裝ipython [[email protected] soft]# ls 51CTO下載-ipython-1.2.1.tar.gz [[email protected] soft]# tar xf 51CTO下載-ipython-1.2.1.tar.gz [[email protected] soft]# ls 51CTO下載-ipython-1.2.1.tar.gz redis-3.2.8.tar.gz ipython-1.2.1 zabbix-2.0.12.tar.gz mongodb-linux-x86_64-rhel62-3.2.7.tgz [[email protected] soft]# cd ipython-1.2.1/ [[email protected] ipython-1.2.1]# ls COPYING.txt examples PKG-INFO scripts setupegg.py setup.py docs IPython README.rst setupbase.py setupext [[email protected] ipython-1.2.1]# python setup.py install //python執行setup腳本,就可以用ipython補全了 三.配置不同操作系統的環境變量 1》配置windows 系統環境變量 win10 操作系統環境變量在一下路徑進行添加可執行程序: 我的電腦---屬性---高級---環境變量--編輯--添加 2》linux系統環境變量配置 例如要添加php命令,php安裝在 /usr/local/webserver/php 下。永久有效添加php命令: [[email protected] ~]# vim /etc/profile //在文件末尾添加如下兩行內容 ......................... ........................ #php export PATH=/usr/local/webserver/php/bin:$PATH [[email protected] ~]# source /etc/profile //是環境變量生效 四.python 從 "hello world"開始 #/usr/bin/python #coding=utf-8 #@Time :2017/10/16 8:59 #@Auther :liuzhenchuan #@File :python 從 hello world 開始.py a = ‘hell world‘ print a print ‘###‘*20 name = raw_input(‘please input you name: ‘) print ‘hell world %s‘ % name >>> hell world ############################################### please input you name: liuzhenchuan hell world liuzhenchuan

python 基礎1.1