godot-python
godot-python copied to clipboard
get the godot import available in an external IDE
I want to use an external IDE (pyCharm) with godot-python but it complains obviously about the missing import of godot (and wants to download it with pip which will fail). Do you or anybody here have an idea how to make the godot package available?
Make sure you have the correct interpreter selected in your IDE. In Pycharm is settings > project interpreter.
The interpreter you want to select lives in:
my_godot_project/pythonscript/$PLATFORM/bin/python
$PLATFORM being your os (osx, x11, win, etc)
Hi, I've been using the pythonscript version 0.11 installed via the asset store up until yesterday when I attempted to upgrade to the v0.30.0. I haven't been able to get it to work through godot, and also when I attempt to add the interpreter through PyCharm I get the following error:

I installed the library by importing the zip from the releases section by the way. I'm fairly vanilla with Godot, so this may be user error in how I installed things.
With the v0.11 version, I was able to use PyCharm with this method of adding the interpreter.
(May be fixable by doing something similar to https://github.com/touilleMan/godot-python/issues/153#issuecomment-626983897)
@matheus2740 Thanks a lot for your answer. I indeed first forgot about adding this as python SDK. But I experience similar problems like @apockill. When I try to add a new System SDK and point it to any of the python executables (python3, python3.7, python3.7-m - python is not available) it says that the SDK seems to be corrupt. It probably searches for something it can not find.
Are there some additional steps (e.g. downloading or copying some libraries) necessairy?
Or is this related to #153 where it seems that currently the python binary is not executing well externally?
@apockill @chrisgraf this does indeed look like the python binary for linux is getting compiled with a wonky path to libpython. It should be fixed in macOS, but for linux, at least for now, you should use the LD_PRELOAD hack described in #153 .
@matheus2740 this hack does not work in this case as PyCharm and IDEA have problems to recognize the Python SDK. I tried to wrap the LD_PRELOAD hack into a bash script and disguise it a a python executable but still the IDEs think the SDK is corrupt.
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: 2020-05-12 15:14:55,388 [1144693] ERROR - ns.python.sdk.PythonSdkUpdater - Failed to determine Python's sys.path value:
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: STDOUT:
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: STDERR:
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: com.jetbrains.python.sdk.InvalidSdkException: Failed to determine Python's sys.path value:
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: STDOUT:
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: STDERR:
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.jetbrains.python.sdk.PythonSdkType.getSysPathsFromScript(PythonSdkType.java:450)
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.jetbrains.python.sdk.PythonSdkType.getSysPath(PythonSdkType.java:432)
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.jetbrains.python.sdk.PythonSdkUpdater.evaluateSysPath(PythonSdkUpdater.java:465)
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.jetbrains.python.sdk.PythonSdkUpdater.getLocalSdkPaths(PythonSdkUpdater.java:339)
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.jetbrains.python.sdk.PythonSdkUpdater.updateLocalSdkPaths(PythonSdkUpdater.java:295)
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.jetbrains.python.sdk.PythonSdkUpdater.update(PythonSdkUpdater.java:144)
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.jetbrains.python.sdk.PythonSdkUpdater.updateOrShowError(PythonSdkUpdater.java:259)
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.jetbrains.python.sdk.PythonSdkType.setupSdkPaths(PythonSdkType.java:338)
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil.setupSdk(SdkConfigurationUtil.java:158)
May 12 15:14:55 H853-CG-3D jetbrains-idea.desktop[6811]: #011at com.jetbrains.python.sdk.PySdkExtKt.setup(PySdkExt.kt:180)
If you know a way to use this hack and force PyCharm/IDEA to recognize the SDK please share it! thanks
I haven't tried but maybe launch PyCharm with the LD_PRELOAD set and then try and add the interpreter.
You can try changing the elf binary to the correct path, using the methods described here: https://stackoverflow.com/questions/2759254/how-can-i-change-the-filename-of-a-shared-library-after-building-a-program-that
thanks @matheus2740 ! the fix with patchelf works! (details see #153)
But still the IDE can not completely find the godot package:

I can confirm that one can now (0.40.0) load the python SDK into PyCharm successfully But the imports are still not working. PyCharm is complaining that e.g. exposed is not defined in the init.py of godot.

I have some problem.
@chrisgraf @chip-pragma This feature is still being worked on, but meanwhile I generated some stubs with mypy which should be good enough for some autocompletion, altought not perfect.
Just download, unzip, and put the files alongside their .so/.pxd counterparts in $PROJECT/addons/pythonscript/$PLATFORM/lib/python3.8/site-packages/godot
godot_stubs.zip
Thanks for this @matheus2740 .. there are a lot of autocomplete options available now. While I can confirm that the missing 'Button' import is gone, 'exposed' still can not be found ..
well i am using Visual Studio Code on my linux mint laptop, When i open the script in Editor , it doesnt recognize Vector2d , expose , export functions being import from the godot module Are there any fixes for this ?
Have a same issue with Pycharm

Responding to https://github.com/touilleMan/godot-python/issues/174#issuecomment-647773096
Is there a script to re-generate these bindings against the latest version of Godot? Is this feature still being worked on, or has it been put off in favor of Godot 4 support?