安装 pyenv

参考文档:https://github.com/pyenv/pyenv-installer

在线安装方法

yum install git -y
# pyenv 在安装python的时候是就地编译的,需要下面的依赖,需要提前安装一下。
yum install gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel -y
id python
useradd python
id python
echo "python" | passwd python --stdin
su - python
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
echo 'export PATH="/home/python/.pyenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"'  >> ~/.bash_profile
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
tail -3  ~/.bash_profile
source ~/.bash_profile
which pyenv# 说明:
eval "$(pyenv init -)"  # 初始化pyenv
eval "$(pyenv virtualenv-init -)"   # 初始化虚拟化插件

安装过程中设置环境变量的提示

[python@linux-node1 ~]$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/% Total    % Received % Xferd  Average Speed  Time    Time    Time  CurrentDload  Upload  Total  Spent    Left  Speed
100  148  100  148    0    0    116      0  0:00:01  0:00:01 --:--:--  116
100  2194  100  2194    0    0  1313      0  0:00:01  0:00:01 --:--:--  1313
Cloning into '/home/python/.pyenv'...
......................
​
WARNING: seems you still have not added 'pyenv' to the load path.
​
# Load pyenv automatically by adding
# the following to ~/.bash_profile:
​
export PATH="/home/python/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

离线安装方法

主要的操作就是在github上clone项目的目录

su - python
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
git clone https://github.com/pyenv/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
git clone https://github.com/pyenv/pyenv-update.git ~/.pyenv/plugins/pyenv-update
git clone https://github.com/pyenv/pyenv-which-ext.git ~/.pyenv/plugins/pyenv-which-ext

配置环境变量(注意家目录是哪一个)

vim ~/.bash_profile
export PATH="/home/python/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"source  ~/.bash_profile

pyenv 命令帮助

[root@linux-node1 ~]# su - python
Last login: Tue Sep 11 22:31:33 CST 2018 on pts/0
[python@linux-node1 ~]$
[python@linux-node1 ~]$ pyenv
pyenv 1.2.7
Usage: pyenv <command> [<args>]
​
Some useful pyenv commands are:commands    List all available pyenv commandslocal       Set or show the local application-specific Python versionglobal      Set or show the global Python versionshell       Set or show the shell-specific Python versioninstall     Install a Python version using python-builduninstall   Uninstall a specific Python versionrehash      Rehash pyenv shims (run this after installing executables)version     Show the current Python version and its originversions    List all Python versions available to pyenvwhich       Display the full path to an executablewhence      List all Python versions that contain the given executable
​
See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme
[python@linux-node1 ~]$ 

通过pyenv安装多版本的python

默认pyenv使用的是系统默认的python版本

[python@centos7-scm ~]$python -V
Python 2.7.5

我们可以通过下面的方法来安装多版本的python环境

isntall

查看帮助

pyenv help install

列出所有可用的版本

pyenv install --list

方法1:在线安装指定的版本

pyenv install 3.5.3 -v
pyenv versions   # 查看当前所处的pyhton环境

方法2:使用缓存方式更快地安装(离线安装)

mkdir ~/.pyenv/cache
cd ~/.pyenv/cache
rz 将下面的包拷贝到上面的路径中
Python-3.5.3.tar.xz  Python-3.5.3.tgz   # 由于在安装的时候,默认选择的包不固定,所以这里我们直接将所有的包都拷贝到 ~/.pyenv/cache执行安装命令
pyenv install 3.5.3 -v
pyenv versions    # 查看当前所处的pyhton环境
[python@centos7-scm ~]$pyenv versions
* system (set by /home/python/.pyenv/version)  # 前面有星号 '*' 的是当前使用的版本3.5.3   # 这个是刚刚安装的版本

pyenv的python版本管理控制

提示:
因为pyenv安装的时候只是安装在用户的家目录中,所以pyenv的版本控制(global、local、shell)都是针对同一个用户的

pyenv global(全局设置)

pyenv global 3.5.3  # 设置全局的python版本(慎用,会影响所有受pyenv控制的python环境)
pyenv version  # 查看当前的pyhton环境
pyenv versions  # 查看所有安装的pyhton版本
python -V  # 查看当前的pyhton版本
[python@linux-node1 ~]$ pyenv local 3.5.3
[python@linux-node1 ~]$ pyenv version
3.5.3 (set by /home/python/.python-version)
[python@linux-node1 ~]$ pyenv versionssystem
* 3.5.3 (set by /home/python/.python-version)
[python@linux-node1 ~]$ python -V
Python 3.5.3
[python@linux-node1 ~]$ 

pyenv local(本地设置--基于目录的设置,并且是子目录继承父目录的设置,最实用)

工作中要使用pyenv设置本地的python环境

pyenv local 3.5.3  # 设置本地的python版本
pyenv version  # 查看当前的pyhton环境
pyenv versions  # 查看所有安装的pyhton版本
python -V  # 查看当前的pyhton版本

使用 local 设置后,python的版本是和目录绑定的,并且子目录继承父目录的python版本。

[python@linux-node1 ~]$ pwd
/home/python
[python@linux-node1 ~]$
[python@linux-node1 ~]$ tree
.
├── scm
│?? └── test
└── test
​
3 directories, 0 files
[python@linux-node1 ~]$
[python@linux-node1 ~]$ python -V
Python 2.7.5
[python@linux-node1 ~]$ cd scm/
[python@linux-node1 scm]$ python -V
Python 3.5.3
[python@linux-node1 scm]$ cd test/
[python@linux-node1 test]$ python -V
Python 3.5.3
[python@linux-node1 test]$ cd ~/test/
[python@linux-node1 test]$ python -V
Python 2.7.5
[python@linux-node1 test]$ pwd
/home/python/test
[python@linux-node1 test]$ pyenv local 3.6.3
[python@linux-node1 test]$ python -V
Python 3.6.3
[python@linux-node1 test]$ 

pyenv shell(基于会话的设置)

pyenv shell 3.5.3  # 设置当前会话的python版本(只会影响pyenv控制的当前会话的python环境,影响面太小,会话断开就会回到system的环境,不常使用)
pyenv version  # 查看当前的pyhton环境
pyenv versions  # 查看所有安装的pyhton版本
python -V  # 查看当前的pyhton版本

Virtuaenv 虚拟环境

为什么要使用虚拟环境?
因为刚才使用的python环境都是一个公共的空间,如果有多个项目使用不同的py“”thon版本开发,或者使用不同的python版本部署运行,或者使用同样的版本开发的但不同项目使用了不同版本的库,等等这些问题都会带来冲突,最好的解决办法就是每一个项目独立运行自己的"独立小环境"中。

虚拟环境的安装使用

1 创建一个虚拟环境

pyenv virtualenv 3.5.3 scm353

2 查看python虚拟环境,会有一个 scm353

[python@centos7-scm ~]$pyenv versions
* system (set by /home/python/.pyenv/version)3.5.33.5.3/envs/scm353scm353

实际上是复制了一个单独的版本,并创建了一个软连接文件指向一该版本

[python@centos7-scm ~]$ll /home/python/.pyenv/versions
total 0
drwxr-xr-x 7 python python 68 Dec 25 21:58 3.5.3
lrwxrwxrwx 1 python python 46 Dec 25 22:12 scm353 -> /home/python/.pyenv/versions/3.5.3/envs/scm353
[python@centos7-scm ~]$ll /home/python/.pyenv/versions/3.5.3/envs/scm353
total 4
drwxrwxr-x 2 python python 186 Dec 25 22:27 bin
drwxrwxr-x 2 python python   6 Dec 25 22:27 include
drwxrwxr-x 3 python python  23 Dec 25 22:27 lib
lrwxrwxrwx 1 python python   3 Dec 25 22:27 lib64 -> lib
-rw-rw-r-- 1 python python  99 Dec 25 22:27 pyvenv.cfg
[python@centos7-scm ~]$

3 切换到指定的项目目录下,执行命令 pyenv local mag353 设定python虚拟环境版本

[python@linux-node1 test]$ python -V
Python 3.6.3
[python@linux-node1 test]$ pyenv local scm353
(scm353) [python@linux-node1 test]$
(scm353) [python@linux-node1 test]$ python -V
Python 3.5.3
(scm353) [python@linux-node1 test]$
(scm353) [python@linux-node1 test]$ cd
[python@linux-node1 ~]$
[python@linux-node1 ~]$ cd -
/home/python/test
(scm353) [python@linux-node1 test]$ 

4 删除指定的虚拟环境

pyenv uninstall scm353

5 导出包
虚拟环境的好处就在于和其他项目运环境隔离,每一个独立的环境都可以使用pip命令导出已经安装好的包,在另一个环境中安装这些包。

pip freeze > requirement

6 在新的虚拟环境中安装上面的包
可以在不同版本的环境中安装

pip install -r requirement

关于虚拟环境的说明

实际上虚拟环境就是在原来的环境中独立出一个小的环境,以后使用该环境的项目中使用的所有包组都是安装在这个小的环境中的site-packages目录中,这样就实现了环境的隔离。

1 没有虚拟环境的时候,所有的包组都是安装在下面的目录中

/home/python/.pyenv/versions/3.5.3/lib/python3.5/site-packages/

2 安装有虚拟环境,使用某个虚拟环境的项目的所有的包组都是安装在下面的目录中

/home/python/.pyenv/versions/3.5.3/envs/scm353/lib/python3.5/site-packages/

ipython 增强的交互式Python命令行工具

提示:

ipython的安装需要切换到安装了pip命令的虚拟环境的目录中去,系统默认的python环境没有安装pip命令

[python@centos7-scm ~]$pip install ipython
pyenv: pip: command not foundThe `pip' command exists in these Python versions:3.5.33.5.3/envs/scm353scm353[python@centos7-scm ~]$pyenv version
system (set by /home/python/.pyenv/version)
[python@centos7-scm ~]$

配置pip的国内镜像

安装Ipython使用到的是pip包管理器,由于网络原因需要配置一下国内的镜像

su - python
mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com
EOF

验证是否可以使用配置的镜像安装的方法:在不同的虚拟环境中,安装redis包,使用pip list看看效果。

pip -V
pip install pkgname  # 是以后经常要使用的安装python包的命令

windows系统 windows下pip的配置文件在~/pip/pip.ini,内容同上

安装ipython

cd test  #
pip install ipython  # 安装ipython
ipython   # 启动Ipython
pip install --upgrade pip   # 最后可能会有更新的提示,建议操作一下,否则后面会经常有提示

出现下面的问题需要更新一下 pip

演示

[python@centos7-scm ~]$cd test
(scm353) [python@centos7-scm test]$pip install ipython
Collecting ipythonDownloading https://mirrors.aliyun.com/pypi/packages/f0/b4/a9ea018c73a84ee6280b2e94a1a6af8d63e45903eac2da0640fa63bca4db/ipython-7.2.0-py3-none-any.whl (765kB)100% |████████████████████████████████| 768kB 183kB/s
......
You are using pip version 9.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(scm353) [python@centos7-scm test]$
(scm353) [python@centos7-scm test]$ipython
Python 3.5.3 (default, Dec 25 2018, 10:48:30)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.In [1]:In [1]:

jupyter 的安装使用

jupyter 是基于WEB 的交互式笔记本,其中可以非常方便地使用python
安装Jupyter的时候会自动安装ipython的

安装Jupyter

su - python
pip install jupyter

常用命令

su - python
jupyter notebook --help
jupyter notebook password
输入密码
jupyter notebook password
jupyter notebook   # 默认是监听在 127.0.0.1 上的8888端口
netstat -lntup jupyter notebook --ip=0.0.0.0 --port=8888  # 指定监听所有地址(0.0.0.0)

启动jupyter (注意关闭防火墙)

(mag353) [python@linux-node1 scm]$ jupyter notebook --ip=0.0.0.0 --port=8888
[I 07:08:18.080 NotebookApp] Serving notebooks from local directory: /home/python/scm
[I 07:08:18.080 NotebookApp] The Jupyter Notebook is running at:
[I 07:08:18.080 NotebookApp] http://(linux-node1.example.com or 127.0.0.1):8888/
[I 07:08:18.080 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 07:08:18.081 NotebookApp] No web browser found: could not locate runnable browser.[I 07:08:32.264 NotebookApp] 302 GET / (192.168.56.2) 1.87ms
[I 07:08:46.938 NotebookApp] Creating new notebook in
[I 07:08:46.965 NotebookApp] Writing notebook-signing key to /home/python/.local/share/jupyter/notebook_secret
[I 07:08:48.735 NotebookApp] Kernel started: 95013ea0-ff49-473e-9001-34b0847e7859
[I 07:08:49.998 NotebookApp] Adapting to protocol v5.1 for kernel 95013ea0-ff49-473e-9001-34b0847e7859
[I 07:10:48.600 NotebookApp] Saving file at /Untitled.ipynb
[I 07:11:06.071 NotebookApp] Saving file at /Untitled.ipynb
[I 07:11:09.719 NotebookApp] Saving file at /Untitled.ipynb
[I 07:12:22.409 NotebookApp] Saving file at /Untitled.ipynb
[I 07:12:47.911 NotebookApp] Saving file at /Untitled.ipynb
[I 07:13:26.105 NotebookApp] Saving file at /Untitled.ipynb
[I 07:14:28.230 NotebookApp] Saving file at /Untitled.ipynb
[I 07:14:37.027 NotebookApp] Starting buffering for 95013ea0-ff49-473e-9001-34b0847e7859:7820a0037d2c467081d28217dbb54482
[I 07:14:40.873 NotebookApp] Adapting to protocol v5.1 for kernel 95013ea0-ff49-473e-9001-34b0847e7859
[I 07:15:07.229 NotebookApp] Adapting to protocol v5.1 for kernel 95013ea0-ff49-473e-9001-34b0847e7859
[I 07:17:07.181 NotebookApp] Saving file at /Untitled.ipynb
[I 07:17:29.435 NotebookApp] Saving file at /Untitled.ipynb

浏览器访问

http://192.168.27.100:8888

输入上面设置的密码


界面展示



本文链接:https://www.cnblogs.com/shichangming/p/10171575.html

转载于:https://www.cnblogs.com/shichangming/p/10171575.html

pyenv、ipython、jupyter的安装使用相关推荐

  1. ipython jupyter区别_ipython jupyter notebook中显示图像和数学公式实例

    1. # 可以使用LaTeX表示数学公式 # 可以使用LaTeX表示数学公式 from IPython.display import Latex Latex(r"$\sqrt{x^2+y^2 ...

  2. Window10环境下的Jupyter notebook安装与打开默认路径的修改

    一.jupyter notebook是什么 官网的介绍是:Jupyter Notebook是一个Web应用程序,允许您创建和共享包含实时代码,方程,可视化和说明文本的文档. 用途包括:数据清理和转换, ...

  3. 如何导入外部代码_如何使用PyQt内联和绘图-Matplotlib与IPython / Jupyter

    有许多不同的Python数据可视化库.但是,在所有库中,Matplotlib很容易成为最受欢迎和使用最广泛的库.使用Matplotlib,您可以创建简单和复杂的可视化文件. Jupyter笔记本是共享 ...

  4. PyCharm使用技巧(五):在PyCharm中使用IPython / Jupyter Notebook

    PyCharm v2018.2最新版本下载 在PyCharm中使用IPython / Jupyter Notebook 在你开始之前 在执行本教程的任务之前,请确保满足以下先决条件: 您已经创建了一个 ...

  5. ipython安装教程-IPython notebook详细安装教程

    IPython从4.0开始,为了项目的独立运行,便将notebook等一系列附加组件迁移至jupyter中,从而使得IPython专注于交互式python这一功能.让我们来看看官网上的解释: &quo ...

  6. 解决Jupyter notebook安装后不自动跳转网页的方法

    解决Jupyter notebook安装后不自动跳转网页的方法 参考文章: (1)解决Jupyter notebook安装后不自动跳转网页的方法 (2)https://www.cnblogs.com/ ...

  7. Windows下的Jupyter Notebook 安装与自定义启动(图文详解)

    1.Jupyter Notebook 和 pip 为了更加方便地写 Python 代码,还需要安装 Jupyter notebook. 利用 pip 安装 Jupyter notebook. 为什么要 ...

  8. Win7环境下IPython Notebook的安装

    前言 学习<Python数据挖掘入门到实践>这本书的过程中,刚开始书中介绍了IPython Notebook的安装方法,但按照书上的方法安装IPython Notebook的过程可谓一波三 ...

  9. anaconda moviepy_Anaconda、Jupyter Notebook安装与使用

    一.为什么学习Python? Python应用范围广,效率高,是排名前五的流行编程语言.对于想从事数据分析.机器学习相关工作或是对这块感兴趣的人,Python是我们需要学会的一种编程语言.学会它,你就 ...

最新文章

  1. php程序里的configini_php中配置文件操作 如config.php文件的读取修改等操作
  2. mysql sql查询json数据_mysql如何查询json的值
  3. Python 使用 smtp ssl 模式 发送邮件与附件
  4. OFD文件结构--带签名
  5. 优麒麟 使用samba的windows打印机_优麒麟 19.10 将于本月结束生命周期
  6. 今天的天气好热哦!!!
  7. TortoiseSVN的安装和使用
  8. 三年后见!雷军透露年轻人的第一台汽车售价......
  9. 【转】adns解析库——域名解析实例(C++、linux)
  10. 那些年,备胎一起追的女神
  11. 移动网速测试软件,网速测试大师APP
  12. MATLAB公式希腊字母表
  13. 粒子群算法 java_粒子群算法解决TSP问题
  14. 专门查英语单词的软件_有什么软件可以查英语单词
  15. 程序员群嘲红芯浏览器:注释过度很业余 创新混淆视听
  16. distiller的另一个实例正忙于启动_PYQT5学习(02):利用Qt Designer制作第一个窗口程序
  17. 计算机字体渲染的学问
  18. 2018.12.30【NOIP提高组】模拟A组 JZOJ 5353 村通网
  19. Unity 自定义圆形图片
  20. vacuum命令详解

热门文章

  1. 输入某年某日,判断这一天是这一年的第几天
  2. Python基础入门实验3附加题
  3. MC(monitorcat) 监控军刀
  4. 硬件钱包 Ledger使用教程
  5. 概率论知识回顾(十):二维连续随机变量分布函数和联合密度函数
  6. Warning: To load an ES module, set “type“: “module“ in the package.json or use the .mjs extension.
  7. java sort 降序_详解Java sort()数组排序(升序和降序)
  8. EIGamal encryption VS Pairing encryption
  9. TWaver HTML5 高性能拓扑
  10. 【20211207】【雷达】毫米波雷达(一)—— 基本原理