python多版本控制

本文详细介绍了如何在Linux环境下安装Git、Python及相关依赖,并通过pyenv进行Python版本管理和虚拟环境的搭建,最后还介绍了如何配置pip源及安装常用库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1安装git

# yum install git -y 

 

2.安装python依赖

# yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel

3.创建python用户

# useradd python
# cd /home/python

4.下载安装pyenv

$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash

5.在python用户bash_profile中添加环境变量

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

  

2.1pyenv基本命令

   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

$ pyenv help install 列出所有可用版本 $ pyenv install --list
$ pyenv version	显示当前版本的python版本
$ pyenv versions 显示所有可用的python版本和当前版本
$ pyenv global 3.5.3	所有的窗口都是3.5.3版本(root用户),pyenv global system 切换会系统默认python版本
$ pyenv shell 3.5.3	只作用于当前会话
$ pyenv local 3.5.3	生效于当前目录并向下递归目录生效

2.2通过pyenv安装python各种版本

$ mkdir /home/.pyenv/cache
$ rz 3.5.3(python包的名字)
$ pyenv install 3.5.3

2.3virturalenv虚拟环境设置

$ pyenv virtualenv 3.5.3 harden3.5.3	虚拟环境3.5.3

2.4pip设置

$ mkdir ~/.pip 配置文件在~/.pip/pip.conf
	[global] index-url=https://mirrors.aliyun.com/pypi/simple/ 
	trusted-host=mirrors.aliyun.com
$ pip install ipython 

2.5用pip安装jupyter

$ pip install jupyter 
$ jupyter notebook help 
$ jupyter notebook password
$ jupyter notebook --ip=0.0.0.0 --no-browser 

2.6导出包

(harden3.5.3) [python@node web]$ pip freeze > requirement 
(harden3.5.3) [python@node web]$ mkdir ~/magedu/projects/pro1 
(harden3.5.3) [python@node web]$ cd ~/magedu/projects/pro1 
[python@node pro1]$ pyenv install --list 
[python@node pro1]$ pyenv install 3.6.4 
[python@node pro1]$ pyenv virtualenv 3.6.4 mag364 
[python@node pro1]$ pyenv local mag364 (mag364) 
[python@node pro1]$ mv ../web/requirement ./ 

  

 

 

 

 

 

 

  

转载于:https://www.cnblogs.com/harden13/p/8611904.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值