Python開發環境#
開始開發程式之前均需安裝程式開發環境,所謂的「開發環境」是一支程式,安裝後讓你可以執行你所撰寫的程式碼。然而,程式開發環境實際上非常多種,支援的功能差異也很大,因此有不少工程師均有他自己選擇或喜好的開發環境(例如我喜歡用Anaconda和Jupyter notebook來做教學,但我喜歡用pyCharm來做我的專案)。
Colab#
Anaconda 3.x#
本課程將使用python 3.x版本、以Anaconda來安裝Python套件、以jupyter notebook為教學環境,因此請上Anaconda網站 https://www.anaconda.com/download/ 下載符合你的作業系統的Python3.x Anaconda版本。並觀看以下說明了解要如何使用Anaconda IDE
1.下載並安裝Anaconda https://docs.anaconda.com/anaconda/install/
2.如何使用Anaconda Navigator https://docs.anaconda.com/anaconda/navigator/
Tip. 你可以上網搜尋「install anaconda」或「using jupyter notebook」,可以在youtube找到相當多的教學影片,教你如何安裝或啟用jupyter notebook
使用conda指令來安裝或更新套件#
通常一個程式語言的執行會啟動其預載的基本套件,讓你可以使用該程式語言的基本功能,如資料結構、流程控制,以及部分的數學函式。而要做更多的科學計算、資料分析或機器學習就要仰賴第三方所開發的套件,這些套件如numpy、matplotlib、pandas、beautifulsoup4、gensim等,都需要先安裝在電腦上,並在程式碼執行前,加載入現下的執行環境才可以使用這些套件所提供的函式。Anaconda提供了一套便利的安裝方式,可以在Mac上的Terminal或Win上的CMD的命令列輸入conda指令就安裝所需要的套件。所謂安裝的概念是把該套件從遠端第三方伺服器上載回你的電腦並安裝在你電腦裡,但這不代表你的程式已經可以開始使用它了,每次你要執行該程式的時候,都還必須要載入(import)它才可以開始使用。請見以下Anaconda的官方說明了解要如何用conda安裝與更新python套件。https://conda.io/docs/user-guide/getting-started.html
jupyter notebook#
下載課程內容: P4CSS/PSS
開啟jupyter notebook: 開啟cmd.exe (wins) 或terminal.app (osx),並輸入
jupyter notebook以啟動他。
Open cmd.exe (wins) or terminal.app (osx), type jupyter notebook to start it
也可以打開Anaconda Navigator,然後選擇Jupyter notebook執行它。

Open Anaconda-Navigator then Start the jupyter notebook
啟動後命令視窗(cmd.exe或terminal.app)會出現一段有token的網址,請記得有這回事,當不小心關掉所有視窗後,只要用這段網址貼在網址列就可以重新打開jupyter notebook。

Copy/paste the URL into your browser to open the jupyter notebook
快速鍵jupyter notebook#
Shift + Enterrun the current cell, select belowCtrl + Enterrun selected cellsAlt + Enterrun the current cell, insert belowCtrl + Ssave and checkpointEntertake you into edit modeD, D (press the key twice)delete selected cellsEsctake you into command modeYchange the cell type to CodeMchange the cell type to MarkdownAinsert cell aboveBinsert cell below
jupyter lab#
建議jupyter notebook的使用者可直接改用jupyter lab,用法和jupyter notebook一樣,又可以讓存取檔案、操作資料變的更方便。打開Anaconda-Navigator就可以找到JupyterLab,或者直接在Command Line輸入jupyter lab就可以啟動。編輯起來跟jupyter notebook一樣,但可以拖拉Cell,和有完整的Topic-of-content supports,拜訪整個檔案結構也比較方便。
PyCharm#
Applying PyChamr free license for students and faculties. Free Educational Licenses - Community Support (jetbrains.com)
Install PyCharm
Set up Project interpreter of PyCharm to Anaconda existing environment. How to setup PyCharm with an anaconda virtual environment already created | by Aseem Bansal