操做系统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非交互式环境。是在远程来执行的。