20tab / UnrealEnginePython

Embed Python in Unreal Engine 4
MIT License
2.75k stars 750 forks source link

Unable to import modules #654

Closed BrunoXL closed 5 years ago

BrunoXL commented 5 years ago

I' m trying to use vscode as an editor to develop my code. However, pylint says Unable to import 'unreal_engine' [E0401]

Anyone knows how can I configure it properly to fix this error?

dfb commented 5 years ago

The module is effectively built into UE4, you can't import it outside of the editor. Perhaps pylint's ignored-modules option is what you need?

BrunoXL commented 5 years ago

ignore-modules solved pylint errors, but cannot autocomplete my code, for instance.

dfb commented 5 years ago

I'm not one of the project devs, but IMO you're not going to have much luck getting autocomplete to work very well:

1) Any tool that requires Python source for a module to generate autocomplete info isn't going to work because there /is/ no Python source - this is stuff implemented in C++.

2) Any tool that uses runtime introspection to figure out autocomplete info (e.g. IPython) will be able to extract some info, but it will "over generate" autocompletions because most UE4 objects are wrapped in a ue_PyUObject instance when they are passed to your Python code, and so all methods that have been implemented in C++ will always show up in the autocompleter (e.g. your object could be referencing an Actor instance but the autocompleter would find methods that work only on StaticMesh objects).

3) In addition to any methods implemented in C++, it is legal to call BlueprintCallable methods, but these calls happen using UE4's built in introspection system. So, for example, you may have a Python variable that references a UE4 StaticMesh object, and you can call its 'SetMaterial' method. But SetMaterial doesn't actually "exist" on that Python object. Rather, when you try to access it, UEPy goes and dynamically locates the function object and wraps it in a ue_PyUObject instance and returns it to you. The implication here is that an autocomplete tool that queries an object for a list of properties/methods wouldn't ever know that 'SetMaterial' is something you can call.

Anyway, just a heads up to set your expectations - maybe the stuff from (2) above is sufficient; just know that the dynamic nature of UE4 combined with the dynamic nature of Python means an autocomplete tool can't do a lot of discovery on its own (you'd have to use an alternate approach like providing the autocompleter a list of available APIs or something).

nasheetzaman commented 5 years ago

Related issue: https://github.com/20tab/UnrealEnginePython/issues/643