准备环境
安装虚拟环境
安装并更新pip
[root@localhost ~]
[root@localhost ~]
安装虚拟环境和管理工具
[root@localhost ~]
[root@localhost ~]
配置虚拟环境
[root@localhost ~]
root@localhost ~]
export WORKON_HOME=$HOME/.virtualenvs
[root@localhost ~]
[root@localhost ~]
安装Python3.6.5
[root@localhost ~]
[root@localhost operation]
[root@localhost operation]
[root@localhost operation]
[root@localhost operation]
[root@localhost Python-3.6.5]
[root@localhost Python-3.6.5]
[root@localhost Python-3.6.5]
[root@localhost Python-3.6.5]
[root@localhost operation]
[root@localhost operation]
>>> exit()
创建测试文件
[root@localhost operation]
[root@localhost aliyun]
配置定时任务crontab
[root@localhost operation]
* * * * * root source /root/.virtualenvs/test/bin/activate;cd /operation/aliyun;python test.py >> /operation/aliyun/test.log 2>&1 &
[root@localhost operation]
[root@localhost operation]
常用虚拟环境操作命令
- 创建虚拟环境:mkvirtualenv test
- 列出所以虚拟环境:lsvirtualenv -b
- 启动或切换虚拟环境:workon test
- 退出虚拟环境:deactivate
- 删除虚拟环境:rmvirtualenv test
- 导出安装依赖包:pip freeze > requirements.txt
- 导出安装依赖包:pip install -r requirements.txt