Python 安裝 Installing Python

Installing Python???cs109/content

All the labs and assignments in this course are Python-based. This page provides information about configuring Python on your machine.

Step 0The IPython notebook runs in the browser, and works best in Google Chrome. You probably want to use Chrome for assignments in this course

Recommended Method: Anaconda

The Anaconda Python distribution is an easily-installable bundle of Python and many of the libraries used throughout this class. Unless you have a good reason not to, we recommend that you use Anaconda.

Mac/Linux users

Download theappropriate versionof Anaconda

Follow the instructions on that page to run the installer

Test it out: open a terminal window, and typepython, you should see something like

Python 2.7.5 |Anaconda 1.6.1 (x86_64)| (default, Jun 28 2013, 22:20:13)

IfAnacondadoesn't appear on the first line, you are using a different version of Python. See the troubleshooting section below.

Test out the IPython notebook: open a Terminal window, and typeipython notebook. A new browser window should pop up.

ClickNew Notebookto create a new notebook file

Update IPython to the newest version by typingconda update ipythonat the command line

Windows Users

Download theappropriate versionof Anaconda

Follow the instructions on that page to run the installer. This will create a directory atC:\Anaconda

Test it out: start the Anaconda launcher, which you can find inC:\Anacondaor, in the Start menu. Start the IPython notebook. A new browser window should open.

ClickNew Notebook, which should open a new page.

Update IPython to the newest version by opening a command prompt, and typingconda update ipython

Installing additional libraries

Anaconda includes most of the libraries we will use in this course, but you will need to install a few extra ones:

BeautifulSoup

Pattern

Seaborn

MrJob

The recommended way to install these packages is to runpip install BeautifulSoup mrjob pattern seabornon the command line. If this doesn't work, you can download the source code, and runpython setup.py installfrom the source code directory. On Unix machines, either of these commands may requiresudo(i.e.sudo pip install...orsudo python)

Opening IPython Notebooks

To view an IPython notebook, you must first start the IPython notebook server in the directory where the file lives. Simply navigate to this directory at the command prompt, and typeipython notebook. This will open a browser window, listing all theipynbfiles in that directory.

Troubleshooting

ProblemWhen you start python, you don't see a line likePython 2.7.5 |Anaconda 1.6.1 (x86_64)|. You are using a Mac or Linux computer

ReasonYou are most likely running a different version of Python, and need to modify your Path (the list of directories your computer looks through to find programs).

SolutionFind a file like.bash_profile,.bashrc, or.profile. Open the file in a text editor, and add a line at this line at the end:export PATH="$HOME/anaconda/bin:$PATH". Close the file, open a new terminal window, typesource ~/.profile(or whatever file you just edited). Typewhich python-- you should see a path that points to the anaconda directory. If so, runningpythonshould load the proper version

If this doesn't work (typingwhich pythondoesn't point to anaconda), you might be using a different shell. Typeecho $SHELL. If this isn'tbash, you need to edit a different startup file (for example, if ifecho $SHELLgives$csh, you need to edit your.cshrcfile. The syntax for this file is slightly different:set PATH = ($HOME/anaconda/bin $PATH)

ProblemYou are running the right version of python (see above item), but are unable to import numpy.

ReasonYou are probably loading a different copy of numpy that is incompatible with Anaconda

SolutionSee the above item to find your.bash_profile,.profile, or.bashrcfile. Open it, and add the lineunset PYTHONPATHat the end. Close the file, open a new terminal window, typesource ~/.profile(or whatever file you just edited), and try again.

ProblemUnder Windows, you receive an error message similar to the following: "'pip' is not recognized as an internal or external command, operable program or batch file."

ReasonThe correct Anaconda paths might not be present in your PATH variable, or Anaconda might not have installed correctly.

SolutionEnsure the Anaconda directories to your path environment variable ("\Anaconda" and "\Anaconda\Scripts"). Seethis pagefor details.

If this does not correct the problem, reinstall Anaconda.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末戚哎,一起剝皮案震驚了整個濱河市易稠,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌俗扇,老刑警劉巖饰潜,帶你破解...
    沈念sama閱讀 221,695評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件初坠,死亡現(xiàn)場離奇詭異,居然都是意外死亡彭雾,警方通過查閱死者的電腦和手機(jī)碟刺,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,569評論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來薯酝,“玉大人半沽,你說我怎么就攤上這事∥獠ぃ” “怎么了者填?”我有些...
    開封第一講書人閱讀 168,130評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長橄务。 經(jīng)常有香客問我幔托,道長,這世上最難降的妖魔是什么蜂挪? 我笑而不...
    開封第一講書人閱讀 59,648評論 1 297
  • 正文 為了忘掉前任重挑,我火速辦了婚禮,結(jié)果婚禮上棠涮,老公的妹妹穿的比我還像新娘谬哀。我一直安慰自己,他們只是感情好严肪,可當(dāng)我...
    茶點故事閱讀 68,655評論 6 397
  • 文/花漫 我一把揭開白布史煎。 她就那樣靜靜地躺著谦屑,像睡著了一般。 火紅的嫁衣襯著肌膚如雪篇梭。 梳的紋絲不亂的頭發(fā)上氢橙,一...
    開封第一講書人閱讀 52,268評論 1 309
  • 那天,我揣著相機(jī)與錄音恬偷,去河邊找鬼悍手。 笑死,一個胖子當(dāng)著我的面吹牛袍患,可吹牛的內(nèi)容都是我干的坦康。 我是一名探鬼主播,決...
    沈念sama閱讀 40,835評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼诡延,長吁一口氣:“原來是場噩夢啊……” “哼滞欠!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起肆良,我...
    開封第一講書人閱讀 39,740評論 0 276
  • 序言:老撾萬榮一對情侶失蹤筛璧,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后妖滔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體隧哮,經(jīng)...
    沈念sama閱讀 46,286評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡桶良,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,375評論 3 340
  • 正文 我和宋清朗相戀三年座舍,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片陨帆。...
    茶點故事閱讀 40,505評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡曲秉,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出疲牵,到底是詐尸還是另有隱情承二,我是刑警寧澤,帶...
    沈念sama閱讀 36,185評論 5 350
  • 正文 年R本政府宣布纲爸,位于F島的核電站亥鸠,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏识啦。R本人自食惡果不足惜负蚊,卻給世界環(huán)境...
    茶點故事閱讀 41,873評論 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望颓哮。 院中可真熱鬧家妆,春花似錦、人聲如沸冕茅。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,357評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至哨坪,卻和暖如春庸疾,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背当编。 一陣腳步聲響...
    開封第一講書人閱讀 33,466評論 1 272
  • 我被黑心中介騙來泰國打工彼硫, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人凌箕。 一個月前我還...
    沈念sama閱讀 48,921評論 3 376
  • 正文 我出身青樓拧篮,卻偏偏與公主長得像,于是被迫代替她去往敵國和親牵舱。 傳聞我的和親對象是個殘疾皇子串绩,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,515評論 2 359

推薦閱讀更多精彩內(nèi)容