python之window下安裝python2版的pyv8庫 (window install python2 pyv8)

在這篇文章【[Python模塊]Windows環境安裝PyV8並執行js語句:https://blog.csdn.net/sc_lilei/article/details/79946029】的基礎上填坑補充:

在window下安裝那個【python2的pyv8:https://pan.baidu.com/s/1rKPqPVidhHzwLT9eYiqFOw】時出現【 Python version 2.7 required, which was not found in the registry】,參考【https://blog.csdn.net/zklth/article/details/8117207】,就是用你的python2執行以下腳本,然後再去點擊安裝那個pyv8的exe文件。

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()

但運行測試的python腳本又發現一個問題【ImportError: DLL load failed: 找不到指定的模塊。】,參考【win10環境下python3如何使用PyV8:https://www.pythonheidong.com/blog/article/324801/】&【https://github.com/emmetio/pyv8-binaries】這篇文章中提到的python2中只有python2.6才適用,果斷切換到python2.6,不過還是失敗了,算了,暫時擱置了。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章