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

Install multiple python environments of any version in the windows environment

編輯:Python

windows環境下安裝多個任意版本的python環境

  • windows環境下安裝多個任意版本的python環境
  • 下載Python
    • 下載pip
        • step1. 用get-pip下載pip
        • step2. Analyze installed files
        • step3. 使用pip得到報錯" No module named 'pip' "
        • step4. 原因分析和解決方案
    • 其他報錯
        • 1. ERROR: Could not find a version that satisfies the requirement pip

windows環境下安裝多個任意版本的python環境

注意:This tutorial is notpython虛擬環境教程,I will make another issue of virtual environment!!!

安裝方法可以歸結為 [下載python + 下載pip + 導入pycharm環境 + 可選:配置環境變量]

下載Python

其他下載python的方法可以參考:

  • 1.linux環境下安裝多個任意版本的python環境_桃之夭夭ღ的博客
  • 2.任意python版本下載,所有python版本下載的FTP路徑

step1. 下載linux版本的python
從Python官網進入
選擇Downloads - Allreleases

step2. 選擇版本下載
進入到下載頁面
注意點擊的是Release version那一列,我們需要下載的是Window嵌入式包

step3. 選擇Windows embeddable package的壓縮包下載
在Release version鏈接下的Files中

According to the number of digits of your computer,選擇32位的Windows embeddable package (32-bit)

或者64位的Windows embeddable package (64-bit)進行下載.

step4. Unzip to a fixed folder

After the download is complete I unzip itDunder the specified directory of the disk,Unzip it into your own directory according to your own habits.

D:\Program Files (Code)\python-3.9.13-embed-amd64

step5. 必看:!!解壓完成後,We define our unzip directory as this versionpython環境的根目錄.

step6. 運行測試

我們按住shift + 鼠標右鍵,通過power shell打開根目錄

輸入.\python.exe,結果如下

PS D:\Program Files (Code)\python-3.9.13-embed-amd64> .\python.exe
Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
>>> a=1
>>> b=2
>>> a + b
3
>>>

說明python已經安裝成功

嵌入式版的pythonThere is no additional environment,即沒有pip,Installation of third-party libraries could not be performed.

下面介紹pip的安裝

下載pip

First introduce some documentation

  • pip安裝教程:Installation - pip documentation v22.1.2 (pypa.io):有ensurepip和get-pip兩種,但是ensurepipI did not test successfully.
  • get-pip.py源代碼:https://bootstrap.pypa.io/get-pip.py
  • References for this tutorial:使用 embed-amd64 zip Install it by unzipping itpython

step1. 用get-pip下載pip

我們保存get-pip的源代碼到python環境的根目錄,然後在powershell中執行.

PS D:\Program Files (Code)\python-3.9.13-embed-amd64> .\python.exe get-pip.py

step2. Analyze installed files

After the installation is complete, there will be the following two folders

其中,

  • LibStores the source code of various third-party packages

  • ScriptsStored are various executable files,我們的pip和setuptoolsThe executable file is placed here.

step3. 使用pip得到報錯" No module named ‘pip’ "

在python/Scripts文件夾下運行PowerShell,運行pip返回以下信息,發現pip無法使用.

PS D:\Program Files (Code)\python-3.9.13-2\Scripts> .\pip.exe
Traceback (most recent call last):
File "runpy.py", line 197, in _run_module_as_main
File "runpy.py", line 87, in _run_code
File "D:\Program Files (Code)\python-3.9.13-2\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'

step4. 原因分析和解決方案

The default package import search path for this release consists of the root directory pythonXX._pth (XX為版本號)文件決定,The default content of the file is as follows:

python39.zip
.
# Uncomment to run site.main() automatically
#import site

That is, by defaultpythonThe environment will only be frompython39.zip.(python根目錄)Search for importable packages.可以根據自己的需要,Manually modify this file to configure the package import search path.

In order to correctly import custom modules in our program directory,修改python安裝目錄下的python3x._pth文件,新添加一行Lib\site-packages.

再次運行pip命令,一切正常,問題解決.

其他報錯

1. ERROR: Could not find a version that satisfies the requirement pip

原因:The official mirror takes thispip給刪除了 = _ = !.Change the mirror source to solve,且用且珍惜.

python3 get-pip.py -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

  • Other mirror sources can refer to:pip 指定鏡像源 指定版本 批量安裝

  • Reference link for the solution:執行python3 get-pip.py報錯:ERROR: Could not find a version that satisfies the requirement pip ERROR: No_jinli1771的博客-CSDN博客_get-pip.py報錯


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