11月 20, 2020

手動建立 Python 作業環境

1. 官網取得 Windows x86-64 embeddable 版本

2. 編輯 python39._pth:加入 Lib/site-packages 路徑、取消 import site 註解 (之後 pip 會用到)
Lib/site-packages
python39.zip
.
# Uncomment to run site.main() automatically
import site
3. 取得 pip 原始碼,進行安裝 python get-pip.py,會自動建立 [Lib ]與 [Scripts] 兩個目錄。

4. 設定環境變數(Path)
- X:\python3.9
- X:\python3.9\Scripts

5. 測一下 pip 會不會動
> pip list
> pip install requests
> pip -V
pip 20.2.4 from d:\python3.9\lib\site-packages\pip (python 3.9)

> pip show pip
Name: pip
Version: 20.2.4
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: distutils-sig@python.org
License: MIT
Location: d:\python3.9\lib\site-packages

6. 測一下 python 載入套件(import)路徑順序
> python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['D:\\python3.9\\python39.zip', 'D:\\python3.9', 'D:\\python3.9\\lib\\site-packages']

沒有留言:

張貼留言