Python開發環境搭建


Python開發環境搭建

Python安裝

Python是跨平臺的,它可以運行在Windows、Mac和各種Linux/Unix系統上。

檢查系統是否已安裝Python

打開終端

<code>> python --version
Python 2.7.6
/<code>

如果你看到上述顯示,那麼Python2.7是系統的默認版本,需要在看一下Python3是否已經安裝:

<code>> python3 --version
Python 3.6.5
/<code>

如果上述兩個命令均報錯,說明系統沒有安裝Python,請參照後續說明安裝Python。

在Windows上安裝Python

  1. 首先,根據你的Windows版本(64位還是32位)從Python的官方網站下載Python3.X對應的64位安裝程序或32位安裝程序然後,運行下載的exe安裝包(⼀般安裝包會命名為Windows x86-64 executable installer ,將安裝包下載到本地)
  2. 雙擊執⾏安裝時會進⼊下⾯的⻚⾯,注意要勾選“ Add Python 3.x to PATH” 選項,點擊Install Now進⼊下⼀步安裝圖

在Mac上安裝Python

如果你正在使用Mac,系統是OS X>=10.9,那麼系統自帶的Python版本是2.7。要安裝最新的Python 3.X,有兩個方法:方法一:從Python官網下載Python 3.x的安裝程序,下載後雙擊運行並安裝;(與Window安裝類同)方法二:通過HomeBrew安裝。安裝Homebrew, 使Python安裝變的非常簡單. 首先安裝Apple的一些xcode工具:

<code>$ xcode-select --install
/<code>

安裝也需要一定等待時間,依賴於網絡速度,安裝完成後安裝HomeBrew:

<code>$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
/<code>

通過運行命令 brew doctor來驗證是否已安裝成功

<code>$ brew doctor
Your system is ready to brew.
/<code>

接下來通過過HomeBrew 安裝Python輸入如下命令:

<code>$ brew install python3
/<code>

在Linux上安裝Python

下面將基於 Ubuntu來做說明:添加apt倉庫deadsnakes,然後通過apt-get install安裝Python

<code>$ sudo add-apt-repository ppa:fkrull/deadsnakes
$ sudo apt-get update
$ sudo apt-get install python3.5
/<code>

驗證是否安裝成功:

<code>>python
Python 3.6.5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Type "help", "copyright", "credits" or "license" for more information.
>>>
/<code>

看到提示符>>>就表示我們已經在Python交互式環境中了,可以輸入任何Python代碼,回車後會立刻得到執行結果。現在,輸入exit()並回車,就可以退出Python交互式環境(直接關掉命令行窗口也可以)若存在多個Python版本需要注意環境變量設置


分享到:


相關文章: