操做系統python
Linuxgit
osxgithub
推薦使用OSXweb
全部代碼能夠放在Linux上運行sql
IDE & EDITORshell
PyCharmvim
編輯器瀏覽器
Atom 下載後能夠直接使用bash
vimcookie
emacs
推薦使用PyCharm
Python版本 3.4.2
異步部分介紹3.5的'async'和'await'關鍵字
安裝Python
使用pyenv來管理Python環境
安裝pyenv, pyenv是使用bash寫的
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
來下載安裝
通常會先下載下來,然後檢查裏面是否有惡意代碼,沒有則能夠執行,這裏安裝依賴git
mac安裝
brew install git
依賴包問題
1.依賴包的安裝
yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel
2. configure: error: no acceptable C compiler found in $PATH
yum install gcc
3. Build failed: "ERROR: The Python zlib extension was not compiled. Missing the zlib?"
CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install -v 2.7.6
4. /root/.pyenv/plugins/python-build/bin/python-build: line 1326: patch: command not found
yum install patch
pyenv默認是安裝在家目錄的.pyenv下
若是要安裝在其餘目錄,能夠在安裝前使用
export PYENV_ROOT=/PATH 則安裝時,會安裝到指定的PATH下面
安裝好之後,有一些環境變量須要配置
vim ~/.bash_profile
添加下面的內容
#pyenv
#export PYENV_ROOT=/usr/local/opt/pyenv
if which pyenv > /dev/null; then
eval "$(pyenv init -)";
fi
把.bash_profile執行一下
把pyenv命令加入到PATH中
# cat /etc/profile.d/pyenv.sh
export PATH=/root/.pyenv/bin:${PATH}
# . /etc/profile.d/pyenv.sh
pyenv使用
#pyenv install 3.4.2 安裝新的Python環境
# pyenv install --list 查看能夠安裝哪些程序
pyenv全部可用的命令
# pyenv commands
commands
completions
exec
global
help
hooks
init
install
local
prefix
rehash
root
shell
shims
uninstall
version
--version
version-file
version-file-read
version-file-write
version-name
version-origin
versions
whence
which
# pyenv versions
system 系統自帶的Python
* 3.4.2 (set by /root/.python-version)
#pyenv local 3.4.2 當前使用及其全部建立的子目錄下使用3.4.2的Python
在當前目錄下會生成一個.python-version的文件
# cat .python-version
3.4.2
此時pip已經安裝好了
# pip -V
pip 1.5.6 from /root/.pyenv/versions/3.4.2/lib/python3.4/site-packages (python 3.4)
#pyenv global 3.4.2 指定全局Python使用3.4.2的版本,任何一個目錄沒有使用local的話都會使用3.4.2的版本,這對系統上默認安裝的軟件會有影響的,儘可能不要使用系統自帶的Python環境,由於Python版本會跟着系統一塊兒升級,升級事後,若是你的項目不支持新版本的Python則會出錯。
#pyenv virtualenv virtualenv是一個虛擬環境,Python它是基於set的。virtualenv是用來建立虛擬環境的
# pyenv versions
system
* 3.4.2 (set by /root/.python-version)
# pyenv virtualenv 3.4.2 magedu_test
Ignoring indexes: https://pypi.python.org/simple/
Requirement already satisfied (use --upgrade to upgrade): setuptools in /root/.pyenv/versions/3.4.2/envs/magedu_test/lib/python3.4/site-packages
Requirement already satisfied (use --upgrade to upgrade): pip in /root/.pyenv/versions/3.4.2/envs/magedu_test/lib/python3.4/site-packages
Cleaning up...
# pyenv versions
system
* 3.4.2 (set by /root/.python-version)
3.4.2/envs/magedu_test
magedu_test (pyenv比較久的版本是這種形式的)
# pyenv local magedu_test
# pyenv versions
system
3.4.2
3.4.2/envs/magedu_test
* magedu_test (set by /root/.python-version)
激活虛擬環境,pip中的環境也改變了
pyenv activate <pyenv_virtual>
# cat .python-version
magedu_test
# pyenv activate magedu_test0000
pyenv-virtualenv: deactivate
pyenv-virtualenv: activate magedu_test0000
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(magedu_test0000) [root@iptables2 ~]# pip -V pip環境也一塊兒裝了,這個環境裝了,就不用激活activate
pip 1.5.6 from /root/.pyenv/versions/3.4.2/envs/magedu_test0000/lib/python3.4/site-packages (python 3.4)
(magedu_test0000) [root@iptables2 ~]# cat .python-version
magedu_test0000
在虛擬環境中也要安裝ipython
$ cat .bashrc
#export PYENV_VIRTUALENV_DISABLE_PROMPT=1
時會用提示(magedu_test0000), 此時己進入你指定的虛擬環境
退出和切換虛擬環境只須要,pyenv activate version就能夠了,exit也能夠不過會退出登陸
安裝ipython
(magedu_test0000) [root@iptables2 ~]# pip install ipython
安裝jupyter,jupyter之前是ipython的一部分,在ipython發展到4時,就分離出來了
# pip install jupyter
ipython 4以前有一個#ipython notebook 命令
在ipython 4以後是用
#jupyter notebook --ip=0.0.0.0
# jupyter notebook
[I 16:31:01.498 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[I 16:31:01.585 NotebookApp] Serving notebooks from local directory: /root
[I 16:31:01.585 NotebookApp] 0 active kernels
[I 16:31:01.585 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/
[I 16:31:01.585 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 16:31:01.586 NotebookApp] No web browser found: could not locate runnable browser.
^C[I 16:33:22.198 NotebookApp] interrupted
Serving notebooks from local directory: /root
0 active kernels
The Jupyter Notebook is running at: http://localhost:8888/
Shutdown this notebook server (y/[n])? y
[C 16:33:25.108 NotebookApp] Shutdown confirmed
[I 16:33:25.109 NotebookApp] Shutting down kernels
# jupyter notebook --ip=0.0.0.0
[I 16:33:39.073 NotebookApp] Serving notebooks from local directory: /root
[I 16:33:39.073 NotebookApp] 0 active kernels
[I 16:33:39.073 NotebookApp] The Jupyter Notebook is running at: http://0.0.0.0:8888/
[I 16:33:39.073 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 16:33:39.074 NotebookApp] No web browser found: could not locate runnable browser.
[I 16:34:14.901 NotebookApp] 302 GET / (192.168.16.213) 1.60ms
經過瀏覽器訪問 serverip:8888 是一個web版的ipython
點untitled能夠命名標題
Markdown是用來標記註釋的
按Ctrl + enter是執行
Ctrl + Alt 是跳到新的行
查看快捷鍵
在ipython 4以前,ipython和jupyter是同一個項目,在ipython 4以後分開,由於jupyter如今是一個語言無關的,如今jupyter的能支持至少50種語言的web非交互式環境。是在遠程來執行的。