萬盛學電腦網

 萬盛學電腦網 >> Linux教程 >> Linux安裝第三方庫時報錯Python version 2.7怎麼辦?

Linux安裝第三方庫時報錯Python version 2.7怎麼辦?

  Linux系統用戶在安裝第三方庫的時候,突然提示錯誤代碼Python version 2.7 required,which was not found in the registry,遇到這個問題的時候你只需建立一個腳本並執行,即可解決這個問題。

Linux安裝第三方庫時報錯Python version 2.7怎麼辦?

  建立一個文件 register.py 內容如下。 然後執行該腳本

  代碼如下

  import sys

  from _winreg import *

  # tweak as necessary

  version = sys.version[:3]

  installpath = sys.prefix

  regpath = “SOFTWARE\Python\Pythoncore\%s\” % (version)

  installkey = “InstallPath”

  pythonkey = “PythonPath”

  pythonpath = “%s;%s\Lib\;%s\DLLs\” % (

  installpath, installpath, installpath

  )

  def RegisterPy():

  try:

  reg = OpenKey(HKEY_CURRENT_USER, regpath)

  except EnvironmentError as e:

  try:

  reg = CreateKey(HKEY_CURRENT_USER, regpath)

  SetValue(reg, installkey, REG_SZ, installpath)

  SetValue(reg, pythonkey, REG_SZ, pythonpath)

  CloseKey(reg)

  except:

  print “*** Unable to register!”

  return

  print “--- Python”, version, “is now registered!”

  return

  if (QueryValue(reg, installkey) == installpath and

  QueryValue(reg, pythonkey) == pythonpath):

  CloseKey(reg)

  print “=== Python”, version, “is already registered!”

  return

  CloseKey(reg)

  print “*** Unable to register!”

  print “*** You probably have another Python installation!”

  if __name__ == “__main__”:

  RegisterPy()

  上面就是Linux安裝第三方庫報錯的解決方法了,上文就是該腳本的代碼,執行腳本後再安裝第三方庫就不會出現錯誤代碼了。

copyright © 萬盛學電腦網 all rights reserved