1. 安装pip
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install python-pip
-
pip 之所以能够成为最流行的包管理工具,优势:
-
pip显示已安装列表的功能;
-
兼容virtualenv;
-
pip 可以通过 requirements.txt集中管理依赖;
-
pip 能够处理二进制格式(.whl);
-
pip是先下载后安装,如果安装失败,也会清理干净,不会留下一个中间状态。
-
2. 配置pip
- pip国内的一些镜像
第三方 | 源地址 |
---|---|
阿里云 | https://mirrors.aliyun.com/pypi/simple/ |
中国科技大学 | https://pypi.mirrors.ustc.edu.cn/simple/ |
豆瓣(douban) | http://pypi.douban.com/simple/ |
清华大学 | https://pypi.tuna.tsinghua.edu.cn/simple/ |
中国科学技术大学 | http://pypi.mirrors.ustc.edu.cn/simple/ |
- 修改源方法
临时调用
#可以在使用pip的时候在后面加上-i参数,指定pip源
pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple
写入配置文件
mkdir ~/.pip/
cat >> ~/.pip/pip.conf << EOF
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
EOF
升级pip,也可以检验pip是否安装成功
[root@zhanghao .php]# pip install -U pip
Cache entry deserialization failed, entry ignored
Collecting pip
Downloading https://files.pythonhosted.org/packages/8d/07/f7d7ced2f97ca3098c16565efbe6b15fafcba53e8d9bdb431e09140514b0/pip-19.2.2-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 95kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.2
Uninstalling pip-8.1.2:
Successfully uninstalled pip-8.1.2
Successfully installed pip-19.2.2
3. pip使用姿势
从下面命令可以看出我们虚拟环境中安装的模块
(zh-pyenv) [python@k8s-master-210 cmdb]$ pip -V
pip 9.0.1 from /home/python/.pyenv/versions/3.5.3/envs/zh-pyenv/lib/python3.5/site-packages (python 3.5)
(zh-pyenv) [python@k8s-master-210 cmdb]$ cd /home/python/.pyenv/versions/3.5.3/envs/zh-pyenv/lib/python3.5/
[python@k8s-master-210 python3.5]$ ls
site-packages
[python@k8s-master-210 python3.5]$ cd site-packages/
[python@k8s-master-210 site-packages]$ ls
__pycache__ easy_install.py pip pip-9.0.1.dist-info pkg_resources redis redis-2.10.6.dist-info setuptools setuptools-28.8.0.dist-info
3.1 使用参数
pip < command > [options]
command | 含义 |
---|---|
install | 安装安装包 |
download | 下载安装包 |
uninstall | 卸载安装包 |
freeze | requirements格式输出安装包,可以到其他服务器上执行 pip install -r requirements.txt直接安装软件 |
list | 列出已经安装的包 |
show | 显示包的具体信息 |
search | 查找对应的包 |
wheel | 打包成whell格式 |
hash | 计算包的hash值 |
completion | 生成命令补全配置 |
help | 显示帮助文档 |
3.2 安装paramiko模块
- 安装模块
[root@localhost ~]# pip install paramiko
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting paramiko
Downloading https://mirrors.aliyun.com/pypi/packages/4b/80/74dace9e48b0ef923633dfb5e48798f58a168e4734bca8ecfaf839ba051a/paramiko-2.6.0-py2.py3-none-any.whl (199kB)
|████████████████████████████████| 204kB 307kB/s
Collecting bcrypt>=3.1.3 (from paramiko)
Downloading https://mirrors.aliyun.com/pypi/packages/ad/36/9a0227d048e98409f012570f7bef8a8c2373b9c9c5dfbf82963cbae05ede/bcrypt-3.1.7-cp27-cp27mu-manylinux1_x86_64.whl (59kB)
|████████████████████████████████| 61kB 105kB/s
Collecting pynacl>=1.0.1 (from paramiko)
Downloading https://mirrors.aliyun.com/pypi/packages/b3/25/e605574f24948a8a53b497744e93f061eb1dbe7c44b6465fc1c172d591aa/PyNaCl-1.3.0-cp27-cp27mu-manylinux1_x86_64.whl (762kB)
|████████████████████████████████| 768kB 315kB/s
Collecting cryptography>=2.5 (from paramiko)
Downloading https://mirrors.aliyun.com/pypi/packages/e6/68/50698ce24c61db7d44d93a5043c621a0ca7839d4ef9dff913e6ab465fc92/cryptography-2.7-cp27-cp27mu-manylinux1_x86_64.whl (2.3MB)
|████████████████████████████████| 2.3MB 2.9MB/s
Requirement already satisfied: six>=1.4.1 in /usr/lib/python2.7/site-packages (from bcrypt>=3.1.3->paramiko) (1.9.0)
Collecting cffi>=1.1 (from bcrypt>=3.1.3->paramiko)
Downloading https://mirrors.aliyun.com/pypi/packages/8d/e9/0c8afd1579e5cf7bc0f06fbcd7cdb954cbc0baadd505973949a99337da1c/cffi-1.12.3-cp27-cp27mu-manylinux1_x86_64.whl (415kB)
|████████████████████████████████| 419kB 3.1MB/s
Collecting enum34; python_version < "3" (from cryptography>=2.5->paramiko)
Downloading https://mirrors.aliyun.com/pypi/packages/c5/db/e56e6b4bbac7c4a06de1c50de6fe1ef3810018ae11732a50f15f62c7d050/enum34-1.1.6-py2-none-any.whl
Collecting asn1crypto>=0.21.0 (from cryptography>=2.5->paramiko)
Downloading https://mirrors.aliyun.com/pypi/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)
|████████████████████████████████| 102kB 643kB/s
Collecting ipaddress; python_version < "3" (from cryptography>=2.5->paramiko)
Downloading https://mirrors.aliyun.com/pypi/packages/fc/d0/7fc3a811e011d4b388be48a0e381db8d990042df54aa4ef4599a31d39853/ipaddress-1.0.22-py2.py3-none-any.whl
Collecting pycparser (from cffi>=1.1->bcrypt>=3.1.3->paramiko)
Downloading https://mirrors.aliyun.com/pypi/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz (158kB)
|████████████████████████████████| 163kB 1.4MB/s
Installing collected packages: pycparser, cffi, bcrypt, pynacl, enum34, asn1crypto, ipaddress, cryptography, paramiko
Running setup.py install for pycparser ... done
Successfully installed asn1crypto-0.24.0 bcrypt-3.1.7 cffi-1.12.3 cryptography-2.7 enum34-1.1.6 ipaddress-1.0.22 paramiko-2.6.0 pycparser-2.19 pynacl-1.3.0
- 显示paramiko
[root@localhost ~]# pip show paramiko
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Name: paramiko
Version: 2.6.0
Summary: SSH2 protocol library
Home-page: https://github.com/paramiko/paramiko/
Author: Jeff Forcier
Author-email: [email protected]
License: LGPL
Location: /usr/lib/python2.7/site-packages
Requires: bcrypt, pynacl, cryptography
Required-by:
- 基于当前环境生成requirements.txt
pip freeze > requirements.txt
[root@localhost ~]# cat requirements.txt
asn1crypto==0.24.0
backports.ssl-match-hostname==3.4.0.2
bcrypt==3.1.7
cffi==1.12.3
chardet==2.2.1
configobj==4.7.2
cryptography==2.7
decorator==3.4.0
enum34==1.1.6
ethtool==0.8
iniparse==0.4
ipaddress==1.0.22
lxml==3.2.1
M2Crypto==0.21.1
Magic-file-extensions==0.2
paramiko==2.6.0
pciutils==1.7.3
perf==0.1
pycparser==2.19
pycurl==7.19.0
pygobject==3.22.0
pygpgme==0.3
pyliblzma==0.5.3
PyNaCl==1.3.0
pyOpenSSL==0.13.1
python-augeas==0.5.0
python-dateutil==1.5
python-dmidecode==3.12.2
python-linux-procfs==0.4.9
pyudev==0.15
pyxattr==0.5.1
redhat-access-insights==1.0.13
requests==2.6.0
rhnlib==2.5.65
rhsm==1.19.9
schedutils==0.4
six==1.9.0
slip==0.4.0
slip.dbus==0.4.0
subscription-manager==1.19.21
urlgrabber==3.10
urllib3==1.10.2
yum-metadata-parser==1.1.4
4. 安装iptyon
pip install ipython
###4.1 安装 jupyter
pip install ipython
- notebook
jutyter notebook help
jupyter password
## 修改web端的密码
jupyter notebook --ip=0.0.0.0
#默认ip是绑定在127.0.0.1的这里修改为0.0.0.0
- 启动之后会监听在8888端口
(zh-pyenv) [python@k8s-master-210 cmdb]$ jupyter notebook password
Enter password:
Verify password:
[NotebookPasswordApp] Wrote hashed password to /home/python/.jupyter/jupyter_notebook_config.json
(zh-pyenv) [python@k8s-master-210 cmdb]$ jupyter notebook --ip=0.0.0.0
[I 06:41:41.287 NotebookApp] Writing notebook server cookie secret to /home/python/.local/share/jupyter/runtime/notebook_cookie_secret
[I 06:41:41.665 NotebookApp] Serving notebooks from local directory: /home/python/zhanghao/project/cmdb
[I 06:41:41.665 NotebookApp] 0 active kernels
[I 06:41:41.665 NotebookApp] The Jupyter Notebook is running at:
[I 06:41:41.665 NotebookApp] http://0.0.0.0:8888/
[I 06:41:41.665 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 06:41:41.666 NotebookApp] No web browser found: could not locate runnable browser.
###4.2 web效果