学习python也有一段时间了,总觉得有的东西,你不总结,在你忽略它的时候就会忘掉,而自己又不是一个很没毅力的人,所以中和二者,我想自己不如先给自己定个小目标,比如“先挣他一个亿!”,哈哈,当然这句是玩笑话,我的目标是每天抽半小时到一小时,对自己的所学去做总结,归纳!
- 本系列总结在docker的centos环境下运行,所以,会涉及到docker安装,容器的创建
- pip加速配置
- virtualenv虚拟环境工具使用
docker基础
- docker 安装(ubuntu)
sudo apt-get install docker-io
- 启动docker
sudo systemctl start docker
- 查看docker服务启动状态
zlx@zlx-Inspiron-5547:~$ sudo systemctl status docker
docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor p
Active: active (running) since 二 2017-08-08 17:10:39 CST; 1h 12min a
Docs: https://docs.docker.com
Main PID: 8142 (dockerd)
Tasks: 41
Memory: 31.8M
CPU: 3.978s
CGroup: /system.slice/docker.service
├─8142 /usr/bin/dockerd -H fd://
├─8156 containerd -l unix:///var/run/docker/libcontainerd/doc
├─8519 containerd-shim e7e5d6331fbf624a043ee04507fbfd0cb01a55
└─8745 containerd-shim e7e5d6331fbf624a043ee04507fbfd0cb01a55
8月 08 17:10:39 zlx-Inspiron-5547 dockerd[8142]: time="2017-08-08T17:10:
8月 08 17:10:39 zlx-Inspiron-5547 systemd[1]: Started Docker Application
安装启动完docker,接下来就是pull镜像,创建容器
- 采用国内docker镜像源,我使用的是网易,查看pull下来的images
zlx@zlx-Inspiron-5547:~$ sudo docker pull hub.c.163.com/public/centos:6.5-tools
zlx@zlx-Inspiron-5547:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hub.c.163.com/public/centos 6.5-tools 97be475c7e56 4 months ago 629.9 MB
- 创建容器
zlx@zlx-Inspiron-5547:~$ sudo docker run -itd --restart=always --name python-stady hub.c.163.com/public/centos /bin/bash
Unable to find image 'hub.c.163.com/public/centos:latest' locally
latest: Pulling from public/centos
96057de2d572: Already exists
a3ed95caeb02: Already exists
8a1dcc3f76c2: Already exists
8fe56c90e86a: Already exists
43fc3558431f: Already exists
5881bc109689: Already exists
Digest: sha256:75a27ccbfdef28456d98134cf04f2f41f76b435d9e62c678c6791af467d6b1b0
Status: Downloaded newer image for hub.c.163.com/public/centos:latest
e7e5d6331fbf624a043ee04507fbfd0cb01a555d1a70000d65e369120ac91210
zlx@zlx-Inspiron-5547:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e7e5d6331fbf hub.c.163.com/public/centos "/bin/bash" 27 seconds ago Up 25 seconds 22/tcp python-stady
- 进入容器
zlx@zlx-Inspiron-5547:~$ sudo docker exec -it python-stady /bin/bash
[root@e7e5d6331fbf /]#
初始化docker容器,因为docker容器只保留,创建docker容器者认为最重要的环境组件,所以一些基础的工具都没有安装,在此,我们是用于一个虚拟的学习环境,所以,一些基础的工具还是有必要安装一下
yum install wget vim links -y #安装wget vim
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo # 使用阿里云epel源
yum install python-pip # 安装pip
pip加速,pip默认的下载服务器在国外,为了能流畅的安装python的模块,我们把pip的源换成国内
- 第一种 参数形式,例如我们安装一个requests库
pip install requests -i http://mirrors.aliyun.com/pypi/simple/
- 第二种,修改配置文件(推荐使用)
[root@e7e5d6331fbf ~]# cat .pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
- 测试,可以看到下载速度很快,所以建议大家把pip源修改成国内,避免在开发过程中,因为下载某个模块而耽误时间
Collecting bpython
Downloading http://mirrors.aliyun.com/pypi/packages/12/11/d33d140ce18dad4c8bc7702dcfcd87280f5c549859ad9054f91df0a0c72d/bpython-0.16-py2.py3-none-any.whl (180kB)
100% |################################| 184kB 1.4MB/s
如果使用pip安装模块时出现error: command 'gcc' failed with exit status 1
yum install gcc libffi-devel python-devel openssl-devel
virtualenv使用(其实我们已经在docker种来运行python了,就不用安装virtaulenv,但是因为实际开发过程中virtualenv会起到很大的作用)
- 安装virtualenv模块
[root@e7e5d6331fbf /]# pip install virtualenv
Collecting virtualenv
Downloading http://mirrors.aliyun.com/pypi/packages/6f/86/3dc328ee7b1a6419ebfac7896d882fba83c48e3561d22ddddf38294d3e83/virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
100% |################################| 1.8MB 3.2MB/s
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0
- 创建虚拟python环境
[root@e7e5d6331fbf /]# virtualenv /opt/python-study --no-site-packages
New python executable in /opt/python-study/bin/python
Installing setuptools, pip, wheel...done.
--no-site-packages 是创建虚拟环境时,不安装site-packages目录下的模块
- 进入虚拟环境目录,激活虚拟环境
[root@e7e5d6331fbf bin]# cd /opt/python-study/bin/
[root@e7e5d6331fbf bin]# source activate
(python-study) [root@e7e5d6331fbf bin]#
至此,今天的内容就先到这里!明天正式按时python的基础只是总结归纳!