问题遇到的现象和发生背景
本人刚开始学习Cocos2dx Lua的相关知识,使用的书籍为《Cocos2d-x实战_Lua卷 _第2版》,cocos版本为3.10。
根据教程,使用Cocos2dx提供的cocos new命令创建项目,却显示某行命令语法错误。
首先进入cocos2dx安装目录\tools\cocos2d-console\bin,之后打开终端。
最开始我确实是这么做的,在命令行直接输入cocos.py,然后直接把我Pycharm打开了……
于是我就改成输入cocos -help,结果如下:
PS D:\Cocos\Cocos2d-x\cocos2d-x-3.10\tools\cocos2d-console\bin> cocos -help
D:\Cocos\Cocos2d-x\cocos2d-x-3.10\tools\cocos2d-console\bin\cocos.py:404: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if cls.get_cocos2d_mode() is not "distro":
Traceback (most recent call last):
File "D:\Cocos\Cocos2d-x\cocos2d-x-3.10\tools\cocos2d-console\bin\cocos.py", line 905, in <module>
if not _check_python_version():
File "D:\Cocos\Cocos2d-x\cocos2d-x-3.10\tools\cocos2d-console\bin\cocos.py", line 869, in _check_python_version
print(MultiLanguage.get_string('COCOS_PYTHON_VERSION_TIP_FMT') % (major_ver, minor_ver))
File "D:\Cocos\Cocos2d-x\cocos2d-x-3.10\tools\cocos2d-console\bin\MultiLanguage.py", line 52, in get_string
fmt = cls.get_instance().get_current_string(key)
File "D:\Cocos\Cocos2d-x\cocos2d-x-3.10\tools\cocos2d-console\bin\MultiLanguage.py", line 46, in get_instance
cls.instance = MultiLanguage()
File "D:\Cocos\Cocos2d-x\cocos2d-x-3.10\tools\cocos2d-console\bin\MultiLanguage.py", line 97, in __init__
self.cfg_info = json.load(f, encoding='utf-8')
File "C:\Users\14563\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
UnicodeDecodeError: 'gbk' codec can't decode byte 0x9a in position 29172: illegal multibyte sequence
之后,我尝试在命令中加入python编译。
命令行窗口报错内容如下(意思是语法错误?):
使用Python2编译是为了避免使用之前安装的Python3编译而做的修改。
D:\Cocos\Cocos2d-x\cocos2d-x-3.10\tools\cocos2d-console\bin>python2 cocos new HelloLua -p com.lua.hello -l lua -d D:/Cocos/new
File "cocos", line 3
COCOS_CONSOLE_BIN_DIRECTORY=$(dirname "$0")
^
SyntaxError: invalid syntax
检查报错中的cocos文件,发现该文件并不是创建工程用的python文件本体,而好像是一个配置文件(文件类型是“文件”)?
文件内容如下:
#!/bin/bash -l
COCOS_CONSOLE_BIN_DIRECTORY=$(dirname "$0")
COCOS_CONSOLE_BIN_DIRECTORY=$(cd "$COCOS_CONSOLE_BIN_DIRECTORY" && pwd -P)
python2 "$COCOS_CONSOLE_BIN_DIRECTORY/cocos.py" "$@"
文件位置如下:
请问各位,我该怎么修改才能正确创建工程呢?谢谢。