python, vs code 导入模块

python, import module in vs code

我为 python 安装了 cocos2d,示例运行良好

但是当我将 python 文件移动到我在 visual studio 代码中选择的文件夹时,它只是说找不到名为 cocos 的模块。

我想我需要更改 launch.json 中的设置,但我不知道如何更改。

我只上传我的 launch.json 文件的一部分。

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Python",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "C:/Users/Sanghun/AppData/Local/Programs/Python/Python35-32/python.exe",
        "program": "${file}",
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ]
    },

您需要修改 settings.json 中的 python.pythonPath 设置以指向此解释器,如下所示: "python.pythonPath":"C:/Users/Sanghun/AppData/Local/Programs/Python/Python35-32/python.exe"

或者您可以只启动命令 'Select Workspace Interpreter' (https://github.com/DonJayamanne/pythonVSCode/wiki/Python-Path-and-Version#selecting-an-interpreter)

最后一点,您可能希望将 launch.json 中的更改还原为以下内容(避免您必须在两个地方指定路径): "pythonPath": "${config.python.pythonPath}",