python之pyenv安装使用

版权声明:如需转载,请注明出处! https://blog.csdn.net/ouyangzhenxin/article/details/81435192

作用:

Pyenv是个多版本Python管理器,可以同时管理多个Python版本共存,让你在编程的时候可以随心所欲的使用不同的python版本;

安装步骤:

1、首先下载pyenv和其所需依赖包;

[root@Linux ~]# yum -y install gcc make patch gdbm-devel openssldevel sqlite-devel readline-devel zlib-devel bzip2-devel 
[root@Linux ~]# git clone git://github.com/yyuu/pyenv.git ~/.pyenv

2、默认下载的位置是你用户家目录下,且是隐藏文件;查看的时候会发现有这些文件(包括但不限于);

[root@Linux ~]# ll -a
......
-rw-r--r--.  1 root root  176 8月   5 20:16 .bash_profile
-rw-r--r--.  1 root root  392 8月   5 20:26 .bashrc
drwxr-xr-x. 13 root root 4096 8月   5 20:16 .pyenv
......

3、配置相关文件,在这个文件中的原有内容下面添加这三行配置信息;

[root@Linux ~]# vim .bashrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

4、重新加载配置文件;

[root@Linux ~]# source .bashrc

5、验证安装成功性;

如果出现如下信息就是安装成功了;

[root@Linux ~]# pyenv
pyenv 1.2.6
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using python-build
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      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

 使用pyenv安装具体版本

1、查看可以安装那些版本;

[root@GZT home]# pyenv install --list
Available versions:
  2.1.3
  2.2.3
  2.3.7
  2.4
  2.4.1
  2.4.2
  2.4.3
  2.4.4
  2.4.5
  2.4.6
  2.5
  2.5.1
  2.5.2
  2.5.3
......

2、安装具体版本;

[root@Linux ~]# pyenv install -v 3.5.0
......
很多安装信息提示,此处省略
......
Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-7.1.2 setuptools-18.2
Installed Python-3.5.0 to /root/.pyenv/versions/3.5.0

/tmp/python-build.20180805204553.95651 ~
~

3、查看是否安装生效;前面有 * 号的说明是当前环境使用的是什么版本的python,此处指的就是默认的版本;

[root@Linux ~]# pyenv versions
* system (set by /root/.pyenv/version)
  3.5.0
[root@Linux ~]#

4、指定当前环境的python环境;然后再次查看的时候就会发现当前的环境变成了3.5.0版本;

[root@Linux home]# pyenv local 3.5.0
[root@Linux home]# pyenv versions
  system
* 3.5.0 (set by /home/.python-version)

5、如何卸载python版本呢;

[root@Linux home]# pyenv uninstall 3.5.0

猜你喜欢

转载自blog.csdn.net/ouyangzhenxin/article/details/81435192
今日推荐