python虚拟环境完美部署教程
作者:一木浮生 发布时间:2021-09-10 17:54:02
一、前言
预处理
建议仔细看完本文章之后在进行操作,避免失误,本环境可以用于生产环境,有利于生产环境python之间的环境隔离,互相不会产生环境冲突;pyenv
和pyenv-virtualenv
可以完美结合使用,具体使用情况看项目具体要求;
依赖环境要求
yum install readline readline-devel readline-static -y
yum install openssl openssl-devel openssl-static -y
yum install sqlite-devel -y
yum install bzip2-devel bzip2-libs -y
yum install libffi-devel -y二、pyenv安装
pyenv获取
[root@tset ~]# git clone https://github.com/yyuu/pyenv.git ~/.pyenv
Cloning into '/root/.pyenv'...
remote: Enumerating objects: 17352, done.
remote: Total 17352 (delta 0), reused 0 (delta 0), pack-reused 17352
Receiving objects: 100% (17352/17352), 3.37 MiB | 24.00 KiB/s, done.
Resolving deltas: 100% (11818/11818), done.配置pyenv系统环境
[root@tset ~]# vim ~/.bashrc
## add by liuchao at 20190806 //添加以下内容
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
//保存退出
[root@tset ~]# source ~/.bashrc //执行配置生效三、pyenv使用
pyenv 安装python版本
个人建议:自己在python官网下载想要安装的版本;首先要在pyenv目录下创建cache文件夹,用来存放python安装包。(可以解决下载安装慢的问题)
[root@tset ~]# mkdir ~/.pyenv/cache //创建cache文件夹,将下载的python安装包存放,
[root@tset ~]# cd ~/.pyenv/cache/
[root@tset cache]# ls //python安装包后缀名必须是.tar.xz
Python-2.7.16.tar.xz Python-3.7.3.tar.xz
pyenv install
[root@tset cache]# cd
[root@tset ~]# pyenv install 3.7.3 -v
/tmp/python-build.20190806095432.10104 ~
/tmp/python-build.20190806095432.10104/Python-3.7.3 /tmp/python-build.20190806095432.10104 ~
Installing Python-3.7.3...
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.7... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for a sed that does not truncate output... /usr/bin/sed
checking for --with-cxx-main=<compiler>... no
checking for g++... no
configure:
检查是否安装成功
[root@tset ~]# pyenv versions
* system (set by /root/.pyenv/version)
3.7.3
更新数据库
[root@tset ~]# pyenv rehash
pyenv切换python版本
[root@tset ~]# pyenv global 2.7.8 // 全局
[root@tset ~]# pyenv local 2.7.8 // 当前目录下
[root@tset ~]# pyenv shell 2.7.8 // shell版本
[root@tset ~]# pyenv shell --unset // 取消当前的shell设定的版本
#创建垫片路径(为所有已安装的可执行文件创建 shims,如:~/.pyenv/versions/*/bin/*,因此,每当你增删了 Python 版本或带有可执行文件的包(如 pip)以后,都应该执行一次本命令)
[root@tset ~]# pyenv rehash
安装与卸载
[root@tset ~]# pyenv install -l # 查看可安装的版本
[root@tset ~]# pyenv install 2.7.8 # 安装python2.7.8的版本
[root@tset ~]# pyenv rehash # 安装模块后
[root@tset ~]# pyenv pyenv uninstall 2.7.8 # 卸载
四、pyenv-virtualenv
安装pyenv-virtualenv
[root@tset ~]# git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
Cloning into '/root/.pyenv/plugins/pyenv-virtualenv'...
remote: Enumerating objects: 2064, done.
remote: Total 2064 (delta 0), reused 0 (delta 0), pack-reused 2064
Receiving objects: 100% (2064/2064), 580.31 KiB | 17.00 KiB/s, done.
Resolving deltas: 100% (1413/1413), done.环境配置
[root@tset ~]# echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
[root@tset ~]# source ~/.bash_profile使用方法
[root@tset ~]# pyenv virtualenv 2.7.10 env-2.7.10 //创建虚拟环境
[root@tset ~]# pyenv activate env-2.7.10 //激活虚拟环境
[root@tset ~]# pyenv deactivate //退出虚拟环境
[root@tset ~]# pyenv uninstall env-2.7.10 //删除虚拟环境
[root@tset ~]# rm -rf ~/.pyenv/versions/env-2.7.10 //删除真实目录
总结
以上所述是小编给大家介绍的python虚拟环境完美部署教程,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://www.cnblogs.com/sky-k/p/11308008.html


猜你喜欢
- 一.环境搭建1.下载安装包访问 Python官网下载地址:https://www.python.org/downloads/下载适合自己系统
- 大家还好吗?背景就不用多说了吧?本来我是初四上班的,现在延长到2月10日了。这是我工作以来时间最长的一个假期了。可惜哪也去不了。待在家里,没
- 一、创建多对多1.学生表create table students ( id int not null primary
- CNN(Convolutional Neural Networks) 卷积神经网络简单讲就是把一个图片的数据传递给CNN,原涂层是由RGB组
- 代码如下:set fso=server.createobject("scripting.filesystemobject"
- MySQL 自4.1版以后开始支持INSERT … ON DUPLICATE KEY UPDATE语法,使得原本需要执行3条SQL语句(SE
- background-clip 和 background-origin 是 CSS3 中新加的 background module 属性,用
- 算法复杂度分为时间复杂度和空间复杂度。其作用: 时间复杂度是指执行算法所需要的计算工作量; 而空间复杂度是指执行这个算法所需要的内存空间。
- Jupyter 是数据分析领域非常有名的开发环境,使用 Jupyter 写数据分析相关的代码会大大节约开发时间。设想这样一个场景:别的部门的
- 本文实例讲述了Python使用当前时间、随机数产生一个唯一数字的方法。分享给大家供大家参考,具体如下:Python生成当前时间很简单,比Ja
- 1、使用专用网站获取的是公网IP网址:http://myip.ipip.net代码:import requestsres = request
- 项目实现利用face++开发一个课堂签到的软件,实现面向摄像头即可完成记录学号、姓名和时间的签到工作。项目架构项目使用场景代码:流程代码,主
- 本文实例讲述了C语言实现访问及查询MySQL数据库的方法。分享给大家供大家参考,具体如下:1、添加头文件路径(MySQL安装路径中的incl
- ltp是哈工大出品的自然语言处理工具箱, pyltp是python下对ltp(c++)的封装.在linux下我们很容易的安装pyltp, 因
- ASP与存储过程(Stored Procedures)的文章不少,但是我怀疑作者们是否真正实践过。我在初学时查阅过大量相关资料,发现其中提供
- //冒泡排序func mpSort(array []int) { for i:=0;i<len(array);i++ {
- 本文通过Python3+PyQt5实现自定义部件–分数滑块。它既能支持键盘也支持鼠标,使用物理(视口)坐标通过绘制方式显示。#!/usr/b
- 举几个例子来介绍一下,Python 的 CSV模块的使用方法,包括,reader, writer, DictReader, DictWrit
- 项目演示:一、输入金额二、跳转到支付宝付款三、支付成功四、跳转回自己网站在使用支付宝接口的前期准备:1、支付宝公钥2、应用公钥3、应用私钥4
- 本文实例讲述了JS+CSS模拟可以无刷新显示内容的留言板功能。分享给大家供大家参考。具体实现方法如下:<!DOCTYPE html P