注意:This tutorial is notpython虛擬環境教程,I will make another issue of virtual environment!!!
安裝方法可以歸結為 [下載python + 下載pip + 導入pycharm環境 + 可選:配置環境變量]
其他下載python的方法可以參考:
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的安裝
First introduce some documentation
我們保存get-pip的源代碼到python環境的根目錄,然後在powershell中執行.
PS D:\Program Files (Code)\python-3.9.13-embed-amd64> .\python.exe get-pip.py
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.
在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'
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命令,一切正常,問題解決.
原因: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報錯