Search code examples
pythonmodulecocos2d-xvisual-studio-code

python, import module in vs code


I installed cocos2d for python and the samples worked well

But when I move the python file into the folder that I selected in the visual studio code, it's only saying that it cannot find the module named cocos.

I guess I need to change the setting in the launch.json but I don't know how.

I'll just upload the part of my launch.json file.

{
"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"
        ]
    },

Solution

  • You will need to modify the python.pythonPath setting in settings.json to point to this interpreter as follows: "python.pythonPath":"C:/Users/Sanghun/AppData/Local/Programs/Python/Python35-32/python.exe"

    Or you could just launch the command 'Select Workspace Interpreter' (https://github.com/DonJayamanne/pythonVSCode/wiki/Python-Path-and-Version#selecting-an-interpreter)

    One last note, you might want to revert the change in launch.json to the following (prevents you from having to specify the path in two places): "pythonPath": "${config.python.pythonPath}",