原文地址:https://www.namidame.tech/No-module-named-yaml.html
在安裝cocos2dx框架之后夏醉,首次使用Lua綁定C++腳本需要安裝配置一些環(huán)境镀梭,可能會出現(xiàn)以下報錯逸寓,針對這些報錯本文提供了相應的解決方法玷禽。
一、缺少yaml模塊
使用Lua綁定C++甫恩,執(zhí)行tools/tolua/genbindings.py時報錯"ImportError: No module named yaml"钾菊,這是因為未安裝yaml模塊羞反,下載安裝yaml模塊即可:
http://pyyaml.org/download/pyyaml/PyYAML-3.10.win32-py2.7.exe
二、python2.7不在注冊表信息里
安裝yaml時出現(xiàn)python version 2.7 required,which was not found in the registry
這是因為注冊表里丟失了python的安裝信息腿倚,用以下方式添加注冊信息即可
新建register.py文件纯出,復制以下內容,保存并運行
#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html
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()
(代碼來自http://www.cnblogs.com/thinksasa/archive/2013/08/26/3283695.html)
運行成功則成功恢復注冊表信息
三敷燎、未安裝Cheetah
安裝yaml后再運行genbindings.py暂筝,報錯ImportError: No module named Cheetah.Template,原因是缺少了cheetah庫硬贯,下載安裝即可
下載Cheetah庫:http://github.com/cheetahtemplate/cheetah/zipball/v2.4.0
- 將下載完的zip文件解壓到任意目錄焕襟,例如C:\Python27\Lib\cheetahtemplate-cheetah-7b1c2ad\
- 命令行依次執(zhí)行以下命令
C:
cd \Python27\Lib\cheetahtemplate-cheetah-7b1c2ad>
python setup.py build
python setup.py install
四、python版本不符
執(zhí)行genbindings.py報錯LibclangError: [Error 193] %1 不是有效的 Win32. To provide e Config.set_library_path() or Config.
按照前面兩步安裝的yaml和Cheetah庫都是win32版本的饭豹,出現(xiàn)這個錯誤是因為python不是win32版本鸵赖,全部都用win32版本即可
下載python win32版本http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi
安裝后重新運行即可
PS.以上下載地址和不同平臺的安裝方法在Python根目錄下的README有說明。
著作權歸作者所有拄衰。
商業(yè)轉載請聯(lián)系作者獲得授權它褪,非商業(yè)轉載請注明出處。
作者: 你很德布羅意
郵箱: namidame@sina.cn
博客地址: https://www.namidame.tech/
原文地址: http://www.namidame.tech/No-module-named-yaml.html