Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get the godot import available in an external IDE #174

Open
chrisgraf opened this issue May 11, 2020 · 15 comments
Open

get the godot import available in an external IDE #174

chrisgraf opened this issue May 11, 2020 · 15 comments

Comments

@chrisgraf
Copy link

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?

@matheus2740
Copy link
Contributor

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)

@apockill
Copy link

apockill commented May 12, 2020

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:

image

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 #153 (comment))

@chrisgraf
Copy link
Author

chrisgraf commented May 12, 2020

@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?

@matheus2740
Copy link
Contributor

@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 .

@chrisgraf
Copy link
Author

chrisgraf commented May 12, 2020

@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

@cridenour
Copy link
Contributor

I haven't tried but maybe launch PyCharm with the LD_PRELOAD set and then try and add the interpreter.

@matheus2740
Copy link
Contributor

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

@chrisgraf
Copy link
Author

thanks @matheus2740 ! the fix with patchelf works! (details see #153)

But still the IDE can not completely find the godot package:

image

@chrisgraf
Copy link
Author

chrisgraf commented Jun 5, 2020

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.

image

@chip-pragma
Copy link

I have some problem.

@matheus2740
Copy link
Contributor

@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

@chrisgraf
Copy link
Author

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 ..

@Suryansh2002
Copy link

Suryansh2002 commented Nov 11, 2021

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 ?

@sHaggYcaT
Copy link

Have a same issue with Pycharm
screenshot from pycharm

@cspotcode
Copy link

Responding to #174 (comment)

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants