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
猜你喜欢
- urllib包和http包都是面向HTTP协议的。其中urllib主要用于处理 URL,使用urllib操作URL可以像使用和打开本地文件一
- 工作时同事间几mb小文件的传输,一般使用QQ或者微信就足够了,但当传输文件几百MB或者几十G时,这种方法的效率就显得不足了。本篇就是简单说明
- pandas处理大数据的限制现在的数据科学比赛提供的数据量越来越大,动不动几十个G,甚至上百G,这就要考验机器性能和数据处理能力。Pytho
- 注意主窗口一定要为tk.Tk(),在主窗口上通过button的点击相应子函数创建子窗口,注意此时创建出来的窗口必须是Toplevel,否则出
- 自动化测试执行的用例有很多,python额测试用例文件,都是以“test”开头的。TestLoader(defaultTestLoader)
- 有三种方法,一是用微软提供的扩展库win32com来操作IE,二是用selenium的webdriver,三是用python自带的HTMLP
- 什么是 Python 中的 Lambda 函数今天我们来学习 Python 中的 lambda 函数,并探讨使用它的优点和局限性Let
- 本文研究的主要是Django1.10文档的深入学习,Applications基础部分的相关内容,具体介绍如下。Applications应用D
- 1. 池的概念主线程:相当于生产者,只管向线程池提交任务。 并不关心线程池是如何执行任务的。线程池:相当于消费者,负责接收任务,并将任务分配
- 前言在算face_track_id map有感:开始验证data={'state':[1,1,2,2,1,2,2,2],
- 本文实例为大家分享了python实现用户名密码校验的具体代码,供大家参考,具体内容如下需要实现功能输入用户名密码 ;认证成功后显示 欢迎信息
- 识别MNIST已经成了深度学习的hello world,所以每次例程基本都会用到这个数据集,这个数据集在tensorflow内部用着很好的封
- 一、if语句if 语句让你能够检查程序的当前状态,并据此采取相应的措施。if语句可应用于列表,以另一种方式处理列表中的大多数元素,以及特定值
- 1.requests库简介requests 是 Python 中比较常用的网页请求库,主要用来发送 HTTP 请求,在使用爬虫或测试服务器响
- 产品使用者可分为三个类别,分别是:初级用户、中级用户、高级用户。这三个类别分别代表了用户使用产品的三个阶段,其中初级用户是占最大比例的,中级
- 简介学习慕课课程,Flask前后端分离API后台接口的实现demo,前端可以接入小程序,暂时已经完成后台API基础架构,使用 postman
- ajax编程获取Google的PageRank3(PR值)及所在目录,想给你的站增加Google PR查询的功能吗?如果你不会就看看本文吧,
- 解析json数据并保存为csv文件首先导入两个包:import jsonimport pandas as pd打开json 文件并读取:wi
- 在互联网出现之前,“抄”很不方便,一是“源”少,而是发布渠道少;而在互联网出现之后,“抄”变得很简单,铺天盖地的“源”源源不断,发布渠道也数
- 如下所示:#!/usr/bin/python3# -*- coding:UTF-8-*-# Author: zhuhongqiangfrom