How to use pyenv to realize Python's perfect version control in Linux

osc_ ytmgp8ea 2020-11-14 11:36:15
use pyenv realize python perfect


Operating system preparation

Get ready Linux The minimum system is enough .
If you clone in a virtual machine ,MAC The address will change .
Use here CentOS 6.5+

install

1, First of all, safety git

yum install git -y

2, install Python Environment depends on

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

3, establish python user

useradd python

4、 Use python Install after user login Pyenv

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

Download the pyenv-installer It's a shell Script . Be careful :

  1. stay https://github.com/pyenv/pyenv-installer There are installation documents
  2. If curl appear curl: (35) SSL connect error , yes nss The problem of low version , Update it . You may need to configure a new package yum Source , Here is /etc/yum.repo/ Add a source , And then update
    [updates]
    name=CentOS-Updates
    baseurl=https://mirrors.aliyun.com/centos/6.9/os/x86_64
    gpgcheck=0
    And then update nss
    yum update nss





5、 stay python User ~/.bash_profile Middle append

 How to use Pyenv stay Linux Realization Python Perfect version control for

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

$ source ~/.bash_profile

So when the user starts , Will execute the user's .bash_profile The script in the , Will start pyenv. Installed pyenv It's just ~/.pyenv in

Pyenv Use

python Version and path route

$ python --version
$ python -V
$ echo $PATH

You can see the current system Python route

pyenv command

 How to use Pyenv stay Linux Realization Python Perfect version control for

$ pyenv help install 
List all available versions 

Online installation python3.5.3 edition

$ pyenv versions This installation may be slow , To speed up , But choose cache Method .
Put the manually downloaded installation package in stay ~/.pyenv/cache Under the table of contents
cache The directory is new
Specifically python The version can be downloaded https://www.python.org/ftp/python/3.5.3/
PS: Download from the official website is reliable



pyenv Of python version control

pyenv Provides three ways of version control , With 3.5.3 give an example

pyenv global 3.5.3 global Set the system to 3.5.3 Linux Mostly based on 2.6 and 2.7 edition , Arbitrarily change , The risk factor is very high , Be careful with !!!
pyenv shell 3.5.3 Only valid for the current reply , Once disconnected, it fails
below , It's a pattern we usually use
pyenv local 3.5.3
local Local settings Use pyenv local Settings inherit this setting recursively from the current working directory .

 How to use Pyenv stay Linux Realization Python Perfect version control for

As shown in figure shows ,pyenv You can actually change the current path python edition , But if a version of pip Management is all together , It's not suitable for project separation .
And that's where it comes in pyenv The packet separation function of

Virtualenv Virtual environment settings

Why use a virtual environment ? As mentioned above , If multiple projects use different Python Version development , Or use a different Python Version deployment run , Or use the same version of the library, but different projects use different versions of the library , And so on, these problems can bring conflicts . The best solution is to run each project independently “ Independent environment ” in .

Let's start with 3.5.3 In the version, a virtual small version comes out

pyenv virtualenv 3.5.3 mt353 

 How to use Pyenv stay Linux Realization Python Perfect version control for

Can exist in the version list , Just like 3.5.3 It's the same , It's just a version . The real catalog is in ~/.pyenv/versions/ Next , In the future, just use this virtual version , The package will follow the corresponding directory , Instead of using 3.5.3.

Then we set up a directory version
As shown in the figure, execute according to the actual demand pyenv local mt353
 How to use Pyenv stay Linux Realization Python Perfect version control for
It can be seen that the current directory has been loaded mt353 edition
In the future, the related package management will be integrated under this version



pip General configuration

pip yes Python Package management tools ,3.x The version of is directly with , You can use it directly . and yun The same for the use of domestic images , The following configuration .

Linux System $ mkdir ~/.pip Configuration file in ~/.pip/pip.conf

[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com

In different virtual environments , install redis package , Use pip list Look at the effect . $ pip -V pip install pkgname command , It is the installation that will be used frequently in the future python The order of the bag

summary

thus , It has been implemented to use pyenv stay Centos 6 The above are python Version control and project separation , Open up the subsequent freedom python project , Any version , Any path ,pip No conflict , Fabulous !

版权声明
本文为[osc_ ytmgp8ea]所创,转载请带上原文链接,感谢

  1. 利用Python爬虫获取招聘网站职位信息
  2. Using Python crawler to obtain job information of recruitment website
  3. Several highly rated Python libraries arrow, jsonpath, psutil and tenacity are recommended
  4. Python装饰器
  5. Python实现LDAP认证
  6. Python decorator
  7. Implementing LDAP authentication with Python
  8. Vscode configures Python development environment!
  9. In Python, how dare you say you can't log module? ️
  10. 我收藏的有关Python的电子书和资料
  11. python 中 lambda的一些tips
  12. python中字典的一些tips
  13. python 用生成器生成斐波那契数列
  14. python脚本转pyc踩了个坑。。。
  15. My collection of e-books and materials about Python
  16. Some tips of lambda in Python
  17. Some tips of dictionary in Python
  18. Using Python generator to generate Fibonacci sequence
  19. The conversion of Python script to PyC stepped on a pit...
  20. Python游戏开发,pygame模块,Python实现扫雷小游戏
  21. Python game development, pyGame module, python implementation of minesweeping games
  22. Python实用工具,email模块,Python实现邮件远程控制自己电脑
  23. Python utility, email module, python realizes mail remote control of its own computer
  24. 毫无头绪的自学Python,你可能连门槛都摸不到!【最佳学习路线】
  25. Python读取二进制文件代码方法解析
  26. Python字典的实现原理
  27. Without a clue, you may not even touch the threshold【 Best learning route]
  28. Parsing method of Python reading binary file code
  29. Implementation principle of Python dictionary
  30. You must know the function of pandas to parse JSON data - JSON_ normalize()
  31. Python实用案例,私人定制,Python自动化生成爱豆专属2021日历
  32. Python practical case, private customization, python automatic generation of Adu exclusive 2021 calendar
  33. 《Python实例》震惊了,用Python这么简单实现了聊天系统的脏话,广告检测
  34. "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system in Python
  35. Convolutional neural network processing sequence for Python deep learning
  36. Python data structure and algorithm (1) -- enum type enum
  37. 超全大厂算法岗百问百答(推荐系统/机器学习/深度学习/C++/Spark/python)
  38. 【Python进阶】你真的明白NumPy中的ndarray吗?
  39. All questions and answers for algorithm posts of super large factories (recommended system / machine learning / deep learning / C + + / spark / Python)
  40. [advanced Python] do you really understand ndarray in numpy?
  41. 【Python进阶】Python进阶专栏栏主自述:不忘初心,砥砺前行
  42. [advanced Python] Python advanced column main readme: never forget the original intention and forge ahead
  43. python垃圾回收和缓存管理
  44. java调用Python程序
  45. java调用Python程序
  46. Python常用函数有哪些?Python基础入门课程
  47. Python garbage collection and cache management
  48. Java calling Python program
  49. Java calling Python program
  50. What functions are commonly used in Python? Introduction to Python Basics
  51. Python basic knowledge
  52. Anaconda5.2 安装 Python 库(MySQLdb)的方法
  53. Python实现对脑电数据情绪分析
  54. Anaconda 5.2 method of installing Python Library (mysqldb)
  55. Python implements emotion analysis of EEG data
  56. Master some advanced usage of Python in 30 seconds, which makes others envy it
  57. python爬取百度图片并对图片做一系列处理
  58. Python crawls Baidu pictures and does a series of processing on them
  59. python链接mysql数据库
  60. Python link MySQL database