程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] python2 and python3 coexist

編輯:Python

1. explain

At present, they are basically used python3 了 , But sometimes I will encounter older projects , Then the sad thing is that you need python2, It is easy to destroy the current python3 Environment , Actually python2 and python3 Yes, it can be installed at the same time , And it's easy to set up

2.Windows System

Go first python Official website https://python.org/ download python2 and python3 Installation package
python3 Try to choose Windows installer (64-bit) Installation procedure ,python2 You can choose msi Installation procedure

Install after downloading python3, Remember to check add to environment variable when installing , The installation process is not difficult , No screenshots. .
after , Start installation python2, Note that it is not added to the environment variable by default , We don't have to change it , We will add it manually later , So we need to remember the installation path

After they are all installed , open cmd or powershell, Input python, It should be possible to enter python3 Environment ,pip It's also python3 Of

We enter python2 Installation path for , And then directly put python.exe Renamed as python2.exe,

We open the environment variable , In turn, open Set up -- System -- About -- Advanced system setup -- environment variable

spot " newly build " You can create new environment variables , And put python2 The installation path of and Script Folders are added to the environment variable , For example, my path here is

C:\Python\Python27
C:\Python\Python27\Scripts


In turn, click “ determine ” Close these windows

restart cmd, Input python2 It should be possible to enter python2 The environment , Then you need to install pip2

python2 -m pip install --upgrade pip --force-reinstall

After it is installed, it can be used pip2 Command management python2 The module

3.Ubuntu20.04

Ubuntu20.04 Self contained python Of 3.X, If you want to python2, You can use commands

# install python2
sudo add-apt-repository universe
sudo apt update
sudo apt install python2
# install pip2
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
sudo python2 get-pip.py
pip2 -V

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved