OSX 10.9.4 如何安裝 Python 2.7?

之前下載了很多個沒有成功。據說自帶 Python 2.7,但是看不懂終端,也不知道在哪裡能找到Python。

我加一個最近安裝的

下載是下載了到目前這一步束手無策。

補充一下,感謝大家的幫助,目前已經能夠使用Python sheet 和終端了,像這樣的

問題是每次編輯只能有一行,也沒有可以引用的函數(是這麼說的吧)

而我想要跟可汗老師一樣的,方便學,而且以前用到過的都是這樣的,編輯和輸出分開功能比較多的

謝謝幫我精簡語言,但還是要有禮貌要謝謝大家的

謝謝大家,我來更新了,想到又能得到大神們的無私幫助真是有些不好意思呢

-------------------------------------

我一直以為%計算是取余(c語言里貌似是『』這個符號)但是8.75%0.5得出0.25的答案真心很糾結啊。我上網查了一下,看到一篇介紹取余和取模的文章(重點在正負號的區別),找不到關於取模的數學知識,有人能給破一下嗎


真鬧心。照著我說的做,不要問為什麼。

打開 Terminal(終端),把這個粘貼進去:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

然後輸入

brew install python

更新:之前少說了一步,不加這一步的話系統不會調用你剛才安裝的Python。

echo export PATH="/usr/local/bin:$PATH" &>&> ~/.bash_profile

如果你希望「Applications」裡面有 Python 自帶的 IDLE 的話,輸入:

brew linkapps

然後下載安裝一個 PyCharm 完事,你想要的就都有了。

Python IDE Django IDE for Web developers : JetBrains PyCharm

===== 以下內容可以不看 =====

===== 以下內容可以不看 =====

===== UPDATE 20140910 0402 =====

@孫志貴 說他那裡有 Timeout 的問題,我就用虛擬機里乾淨的 OS X 10.9.4 完整操作了一遍。

可以試試重新輸入 brew install python 嘗試重新安裝。

我在虛擬機里裝完了 Python 2.7.8,完全按照我給出的命令,也安裝好了,不過確實發現我忽略了一步。

Homebrew 用的 http://sf.net 不是很穩定,所以有時候需要Ctrl-C然後重新輸入 brew install python 來重啟下載。

日誌如下,供參考。加粗是我輸入的部分。

1. 安裝 homebrew

PythonicdeMacBook-Pro:~ pythonic$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
==&> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==&> /usr/bin/sudo /bin/mkdir /usr/local

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Password:
==&> /usr/bin/sudo /bin/chmod g+rwx /usr/local
==&> /usr/bin/sudo /usr/bin/chgrp admin /usr/local
==&> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==&> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==&> Installing the Command Line Tools (expect a GUI popup):
==&> /usr/bin/sudo /usr/bin/xcode-select --install
xcode-select: note: install requested for command line developer tools
Press any key when the installation has completed.
==&> Downloading and installing Homebrew...
remote: Counting objects: 196389, done.
remote: Compressing objects: 100% (53615/53615), done.
remote: Total 196389 (delta 142044), reused 195794 (delta 141599)
Receiving objects: 100% (196389/196389), 40.24 MiB | 52.00 KiB/s, done.
Resolving deltas: 100% (142044/142044), done.
From https://github.com/Homebrew/homebrew
* [new branch] master -&> origin/master
HEAD is now at 4525585 elixir 1.0.0-rc2 (devel)
==&> Installation successful!
==&> Next steps
Run `brew doctor` before you install anything
Run `brew help` to get started

2. 安裝 Python

PythonicdeMacBook-Pro:~ pythonic$ brew install python
==&> Installing dependencies for python: readline, sqlite, gdbm, openssl
==&> Installing python dependency: readline
==&> Downloading https://downloads.sf.net/project/machomebrew/Bottles/readline-6.3.8.mavericks.bottle.tar.gz
######################################################################## 100.0%
==&> Pouring readline-6.3.8.mavericks.bottle.tar.gz
==&> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X provides similar software, and installing this software in
parallel can cause all kinds of trouble.

OS X provides the BSD libedit library, which shadows libreadline.
er to prevent conflicts when programs look for libreadline we are
ting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you"ll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/readline/lib
CPPFLAGS: -I/usr/local/opt/readline/include

==&> Summary
/usr/local/Cellar/readline/6.3.8: 40 files, 2.1M
==&> Installing python dependency: sqlite
==&> Downloading https://downloads.sf.net/project/machomebrew/Bottles/sqlite-3.8.6.mavericks.bottle.tar.gz
######################################################################## 100.0%
==&> Pouring sqlite-3.8.6.mavericks.bottle.tar.gz
==&> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

OS X provides an older sqlite3.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you"ll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/sqlite/lib
CPPFLAGS: -I/usr/local/opt/sqlite/include

==&> Summary
/usr/local/Cellar/sqlite/3.8.6: 9 files, 2.1M
==&> Installing python dependency: gdbm
==&> Downloading https://downloads.sf.net/project/machomebrew/Bottles/gdbm-1.11.mavericks.bottle.tar.gz

curl: (35) Server aborted the SSL handshake
Error: Failed to download resource "gdbm"
Download failed: https://downloads.sf.net/project/machomebrew/Bottles/gdbm-1.11.mavericks.bottle.tar.gz
Warning: Bottle installation failed: building from source.
==&> Downloading http://ftpmirror.gnu.org/gdbm/gdbm-1.11.tar.gz
######################################################################## 100.0%
==&> ./configure --prefix=/usr/local/Cellar/gdbm/1.11 --mandir=/usr/local/Cellar/gdbm/1.11/share/man --infodir=/usr/lo
==&> make install
/usr/local/Cellar/gdbm/1.11: 17 files, 532K, built in 39 seconds
==&> Installing python dependency: openssl
==&> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0.1i.mavericks.bottle.3.tar.gz
######################################################################## 100.0%
==&> Pouring openssl-1.0.1i.mavericks.bottle.3.tar.gz
==&> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs

and run
/usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

The OpenSSL provided by OS X is too old for some software.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you"ll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include

==&> Summary
/usr/local/Cellar/openssl/1.0.1i: 430 files, 15M
==&> Installing python
==&> Downloading https://downloads.sf.net/project/machomebrew/Bottles/python-2.7.8_1.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==&> Pouring python-2.7.8_1.mavericks.bottle.2.tar.gz
==&> Caveats
Setuptools and Pip have been installed. To update them
pip install --upgrade setuptools
pip install --upgrade pip

You can install Python packages with
pip install &

They will install into the site-package directory
/usr/local/lib/python2.7/site-packages

See: https://github.com/Homebrew/homebrew/wiki/Homebrew-and-Python

.app bundles were installed.
Run `brew linkapps` to symlink these to /Applications.

3. 修改優先順序

PythonicdeMacBook-Pro:~ pythonic$ echo export PATH="/usr/local/bin:$PATH" &>&> ~/.bash_profile


最簡單的辦法是:

brew install python


OS X 自帶 Python 2.7.

直接在終端用解釋器執行的話,如圖

執行 .py 腳本的話,

至此,起碼是能夠運行 Python 代碼了。往後,開發環境的搭建,用搜索引擎能夠找到的資料太多了。


樓主今後用10.10也不會再遇到這種問題了。

=========

下文是我按照 @布拤客 所提示的步驟執行之後的終端機訊息,似乎最後一步出錯了…

Last login: Mon Sep 8 23:33:12 on ttys000

Shiki-Suens-rMBP:~ ShikiSuen$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

==&> This script will install:

/usr/local/bin/brew

/usr/local/Library/...

/usr/local/share/man/man1/brew.1

==&> The following directories will be made group writable:

/usr/local/.

/usr/local/bin

/usr/local/lib

/usr/local/share

/usr/local/share/man

==&> The following directories will have their group set to admin:

/usr/local/.

/usr/local/bin

/usr/local/lib

/usr/local/share

/usr/local/share/man

Press RETURN to continue or any other key to abort

==&> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/bin /usr/local/lib /usr/local/share /usr/local/share/man

Password:

==&> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/. /usr/local/bin /usr/local/lib /usr/local/share /usr/local/share/man

==&> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew

==&> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew

==&> Installing the Command Line Tools (expect a GUI popup):

==&> /usr/bin/sudo /usr/bin/xcode-select --install

xcode-select: note: install requested for command line developer tools

Press any key when the installation has completed.

==&> Downloading and installing Homebrew...

remote: Counting objects: 196262, done.

remote: Compressing objects: 100% (53494/53494), done.

remote: Total 196262 (delta 141940), reused 195806 (delta 141595)

Receiving objects: 100% (196262/196262), 40.22 MiB | 2.25 MiB/s, done.

Resolving deltas: 100% (141940/141940), done.

From Homebrew/homebrew · GitHub

* [new branch] master -&> origin/master

HEAD is now at 82170d1 Fix file descriptor leak

==&> Installation successful!

==&> Next steps

Run `brew doctor` before you install anything

Run `brew help` to get started

Shiki-Suens-rMBP:~ ShikiSuen$ brew install python

==&> Installing dependencies for python: pkg-config, readline, sqlite, gdb

==&> Installing python dependency: pkg-config

==&> Downloading http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz

######################################################################## 100.0%

==&> ./configure --prefix=/usr/local/Cellar/pkg-config/0.28 --disable-host-tool -

==&> make

==&> make check

==&> make install

/usr/local/Cellar/pkg-config/0.28: 10 files, 612K, built in 57 seconds

==&> Installing python dependency: readline

==&> Downloading http://ftpmirror.gnu.org/readline/readline-6.3.tar.gz

######################################################################## 100.0%

==&> Downloading https://gist.githubusercontent.com/jacknagel/d886531fb6623b60b2a

######################################################################## 100.0%

==&> Patching

patching file display.c

patching file input.c

patching file misc.c

patching file patchlevel

patching file readline.c

patching file rltypedefs.h

patching file util.c

==&> ./configure --prefix=/usr/local/Cellar/readline/6.3.8 --enable-multibyte

==&> make install

==&> Caveats

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X provides similar software, and installing this software in

parallel can cause all kinds of trouble.

OS X provides the BSD libedit library, which shadows libreadline.

er to prevent conflicts when programs look for libreadline we are

ting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your

own software and it requires this formula, you"ll need to add to your

build variables:

LDFLAGS: -L/usr/local/opt/readline/lib

CPPFLAGS: -I/usr/local/opt/readline/include

==&> Summary

/usr/local/Cellar/readline/6.3.8: 40 files, 2.1M, built in 35 seconds

==&> Installing python dependency: sqlite

==&> Downloading http://sqlite.org/2014/sqlite-autoconf-3080600.tar.gz

######################################################################## 100.0%

==&> ./configure --prefix=/usr/local/Cellar/sqlite/3.8.6 --enable-dynamic-extensi

==&> make install

==&> Caveats

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in

parallel can cause all kinds of trouble.

OS X provides an older sqlite3.

Generally there are no consequences of this for you. If you build your

own software and it requires this formula, you"ll need to add to your

build variables:

LDFLAGS: -L/usr/local/opt/sqlite/lib

CPPFLAGS: -I/usr/local/opt/sqlite/include

==&> Summary

/usr/local/Cellar/sqlite/3.8.6: 9 files, 2.1M, built in 28 seconds

==&> Installing python dependency: gdbm

==&> Downloading http://ftpmirror.gnu.org/gdbm/gdbm-1.11.tar.gz

######################################################################## 100.0%

==&> ./configure --prefix=/usr/local/Cellar/gdbm/1.11 --mandir=/usr/local/Cellar/

==&> make install

/usr/local/Cellar/gdbm/1.11: 17 files, 532K, built in 12 seconds

==&> Installing python dependency: makedepend

==&> Downloading http://xorg.freedesktop.org/releases/individual/util/makedepend-

######################################################################## 100.0%

==&> Downloading http://xorg.freedesktop.org/releases/individual/proto/xproto-7.0

######################################################################## 100.0%

==&> ./configure --disable-silent-rules --prefix=/private/tmp/makedepend-Z76mf6/m

==&> make install

==&> Downloading http://xorg.freedesktop.org/releases/individual/util/util-macros

######################################################################## 100.0%

==&> ./configure --prefix=/private/tmp/makedepend-Z76mf6/makedepend-1.0.5/xorg-ma

==&> make install

==&> ./configure --disable-silent-rules --prefix=/usr/local/Cellar/makedepend/1.0

==&> make install

/usr/local/Cellar/makedepend/1.0.5: 7 files, 92K, built in 19 seconds

==&> Installing python dependency: openssl

==&> Downloading https://www.openssl.org/source/openssl-1.0.1i.tar.gz

######################################################################## 100.0%

==&> perl ./Configure --prefix=/usr/local/Cellar/openssl/1.0.1i --openssldir=/usr

==&> make depend

==&> make

==&> make test

==&> make install MANDIR=/usr/local/Cellar/openssl/1.0.1i/share/man MANSUFFIX=ssl

==&> Caveats

A CA file has been bootstrapped using certificates from the system

keychain. To add additional certificates, place .pem files in

/usr/local/etc/openssl/certs

and run

/usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in

parallel can cause all kinds of trouble.

The OpenSSL provided by OS X is too old for some software.

Generally there are no consequences of this for you. If you build your

own software and it requires this formula, you"ll need to add to your

build variables:

LDFLAGS: -L/usr/local/opt/openssl/lib

CPPFLAGS: -I/usr/local/opt/openssl/include

==&> Summary

/usr/local/Cellar/openssl/1.0.1i: 430 files, 15M, built in 3.0 minutes

==&> Installing python

==&> Downloading http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz

######################################################################## 100.0%

==&> Downloading http://bugs.python.org/file30805/issue10910-workaround.txt

curl: (7) Failed to connect to http://bugs.python.org port 80: Operation timed out

Error: Failed to download resource "python--patch"

Download failed: http://bugs.python.org/file30805/issue10910-workaround.txt

Shiki-Suens-rMBP:~ ShikiSuen$


快用PyCharm吧,jetBrains官網裡直接下載。


誰邀請我來回答這種我沒搞過的事情。

蘋果電腦我也很想買一個來折騰,這不正在存錢么。

這個,題主呢。在Linux 環境中,進入終端後。直接敲入

python

就可以進入Python的命令模式啦!

要不你先試試?

而且呢,python的代碼也可以先寫成 .py 的形式,再直接執行就好啦!用任何純文本格式的編輯器都可以寫。

另外,在Python的官網上是可以下載Python的安裝文件的,直接按照MAC OS 安裝程序的方式安裝就好啦。

自帶的編輯器用著都還行。

不負責任的吹了這麼多,有人看見麻煩留個腳印。我晚上回來在虛擬機裡面搞好了再來正兒八經的給你回答。

以上是平板手打,睡覺了。下午還要砸牆去。。。

一定要有人看見...阿彌陀佛。


這一定是個妹子,大家上。


看起來安裝好了啊,只是提示你的tcl/tk是不穩定的版本。

python3大法好,換成python3吧!


推薦閱讀:

python 3.4 新加入的asyncio是咋通過yield from實現非同步的?
如何看待 Instagram 將所有 Web 後端遷移到 Python 3.6 ?
Python混合類型計算中的一點疑惑?
Python 3.6 有什麼新特性?
Python2轉Python3有沒有必要重新學習?

TAG:macOS | Python | 安裝 | Python入門 |