在windows7上使用python 3.9及更高版本的辦法

lt發表於2021-01-29

python 3.9起,官方不支援在windows7及以下版本中安裝和執行,為了不重灌作業系統,經過嘗試,找到了如下解決辦法。

1.下載非安裝版本 Windows embeddable package (64-bit)
https://www.python.org/ftp/python/3.9.1/python-3.9.1-embed-amd64.zip

2.解壓縮檔案到D:\python39,進入此目錄,執行python,提示缺少api-ms-win-core-path-l1-1-0.dll,從網上下載了一個,將6.2.9200.16384版本放到解壓縮目錄中。
輸出

D:\python39>python
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'python'
  isolated = 1
  environment = 1
  user site = 1
  import site = 0
  sys._base_executable = '\u0158\x08'
  sys.base_prefix = 'D:\\python39'
  sys.base_exec_prefix = 'D:\\python39'
  sys.platlibdir = 'lib'
  sys.executable = '\u0158\x08'
  sys.prefix = 'D:\\python39'
  sys.exec_prefix = 'D:\\python39'
  sys.path = [
    'D:\\python39',
    'D:\\python39',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x0000058c (most recent call first):
<no Python frame>

3.下載原始碼,
https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz
再下載visual studio 2017,自己編譯出python的二進位制檔案。不幸,也是同樣的錯誤。

4.下載python 3.8非安裝版本
https://www.python.org/ftp/python/3.8.7/python-3.8.7-embed-amd64.zip

5.可執行檔案替換
將python 3.8的可執行檔案python.exe解壓縮,複製到D:\python39,替換原有的同名檔案。 執行python,提示缺少python38.dll檔案,將python39.dll重新命名為python38.dll,python39.zip改名為python38.zip。
再次執行,成功。

D:\python39>python    
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

測試3.9版新功能。 https://docs.python.org/zh-cn/3.9/whatsnew/3.9.html

>>> x = {"key1": "value1 from x", "key2": "value2 from x"}
>>> y = {"key2": "value2 from y", "key3": "value3 from y"}
>>> x | y
{'key1': 'value1 from x', 'key2': 'value2 from y', 'key3': 'value3 from y'}

也成功了。

相關文章