熱門文章

2016年8月8日 星期一

Python 安裝 (Mac OS X)

➜  ~ git:(master) pip

zsh: command not found: pip

沒有python


安裝homebrew

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

檢查是否安裝成功
brew -v
Homebrew 0.9.9 (git revision ed9b; last commit 2016-07-13)

安裝python3
brew install python3
==> Installing dependencies for python3: sqlite, gdbm==> Installing python3 dependency: sqlite==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.13.0.el_capitan.bottle.tar.gz######################################################################## 100.0%==> Pouring sqlite-3.13.0.el_capitan.bottle.tar.gz==> CaveatsThis formula is keg-only, which means it was not symlinked into /usr/local.
OS X provides an older sqlite3.
Generally there are no consequences of this for you. If you build yourown software and it requires this formula, you'll need to add to yourbuild variables:
    LDFLAGS:  -L/usr/local/opt/sqlite/lib    CPPFLAGS: -I/usr/local/opt/sqlite/include
==> Summary🍺  /usr/local/Cellar/sqlite/3.13.0: 10 files, 2.9M==> Installing python3 dependency: gdbm==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.12.el_capitan.bottle.tar.gz######################################################################## 100.0%==> Pouring gdbm-1.12.el_capitan.bottle.tar.gz🍺  /usr/local/Cellar/gdbm/1.12: 18 files, 490.7K==> Installing python3==> Downloading https://homebrew.bintray.com/bottles/python3-3.5.2.el_capitan.bottle.tar.gz######################################################################## 100.0%==> Pouring python3-3.5.2.el_capitan.bottle.tar.gz==> /usr/local/Cellar/python3/3.5.2/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python3/3.5.2/bin --install-lib=/usr/local/lib/python3.5/site-packages --si==> /usr/local/Cellar/python3/3.5.2/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python3/3.5.2/bin --install-lib=/usr/local/lib/python3.5/site-packages --si==> /usr/local/Cellar/python3/3.5.2/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python3/3.5.2/bin --install-lib=/usr/local/lib/python3.5/site-packages --si==> CaveatsPip, setuptools, and wheel have been installed. To update them  pip3 install --upgrade pip setuptools wheel
You can install Python packages with  pip3 install <package>
They will install into the site-package directory  /usr/local/lib/python3.5/site-packages
See: https://github.com/Homebrew/brew/blob/master/share/doc/homebrew/Homebrew-and-Python.md
.app bundles were installed.Run `brew linkapps python3` to symlink these to /Applications.==> Summary🍺  /usr/local/Cellar/python3/3.5.2: 3,494 files, 53.2M

測試python
pip

zsh: command not found: pip

還是沒有,結果發現因為是版本3所以要pip3

pip3

Usage:     pip <command> [options]
Commands:  install                     Install packages.  download                    Download packages.  uninstall                   Uninstall packages.  freeze                      Output installed packages in requirements format.  list                        List installed packages.  show                        Show information about installed packages.  search                      Search PyPI for packages.  wheel                       Build wheels from your requirements.  hash                        Compute hashes of package archives.  completion                  A helper command used for command completion  help                        Show help for commands.
General Options:  -h, --help                  Show help.  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.  -V, --version               Show version and exit.  -q, --quiet                 Give less output.  --log <path>                Path to a verbose appending log.  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).  --timeout <sec>             Set the socket timeout (default 15 seconds).  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.  --cert <path>               Path to alternate CA bundle.  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.  --cache-dir <dir>           Store the cache data in <dir>.  --no-cache-dir              Disable the cache.  --disable-pip-version-check                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.



安裝requests 和 BeautifulSoup4


➜  ~ git:(master) pip3 install requests
Collecting requests
  Downloading requests-2.10.0-py2.py3-none-any.whl (506kB)
    100% |████████████████████████████████| 512kB 633kB/s 
Installing collected packages: requests
Successfully installed requests-2.10.0
➜  ~ git:(master) pip3 install BeautifulSoup4
Collecting BeautifulSoup4
  Downloading beautifulsoup4-4.5.1-py3-none-any.whl (83kB)
    100% |████████████████████████████████| 92kB 289kB/s 
Installing collected packages: BeautifulSoup4

Successfully installed BeautifulSoup4-4.5.1


將以上import到python,這邊跟上面一樣要改成"python3"

 ➜  ~ git:(master) python3
Python 3.5.2 (default, Jun 29 2016, 13:43:58) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> from bs4 import BeautifulSoup
>>> 

輸入後 ctrl+Z 跳出
[2]  + 6004 suspended  python3




➜  ~ git:(master) pip3 install "ipython[notebook]"

takes few mins


開啟方法
➜  ~ git:(master) ipython notebook

會自動開啟瀏覽器 or 你可以手動 http://localhost:8888/

沒有留言:

張貼留言