This project has moved and is read-only. For the latest updates, please go here.

Intellisense not working for extension module

May 12, 2014 at 10:19 AM
I have some extension module written in CPython. These are getting attached as project reference very well, but intellisense seems to be not working. If I import the same extensions in interactive window, intellisense works fine. I need set PYTHONPATH before importing these modules and I use custom hook for loading extension modules.

Would you guide me in this problem? I don't know what is going wrong in editor.
May 13, 2014 at 5:56 PM
Are you adding project references to the C++ projects that build the extension? If so, this is not yet properly supported, and you'll need to add a reference directly to the .pyd file as well (in the latest dev build the situation is improved, but still not perfect).

It may also be the custom hook that is causing issues. Can you have a look in C:\Users\<your name>\AppData\Local\Python Tools\References DB and see if you can find a file that looks similar to your module? If there aren't any, or if there are *.idb files that are around 200 bytes, it probably means we can't import the module in our script that we use to get the members. We'll need to hear more about the custom hook in this case.
Nov 5, 2014 at 9:28 AM
Edited Nov 5, 2014 at 10:45 AM
I have a similar problem where I have implemented a python wrapper (called hue.pyd) for our own toolkit library. The wrapper dll loads the toolkit dll upon initialization (via LoadLibrary) and thus has no explicit dependency on the toolkit dll. After I configure a Python Environment with my own Python build, Intellisense for my library works fine in the Interactive Window, but not in the editor window. When I write "import h" in the editor window "hue" comes up as one of the alternatives for autocomplete, so PTVS obviously knows of its existence. I get no further completions though.

In the directory [User9\AppData\Local\Python Tools\CompletionDB\11.0\86fa1b06-d51a-4599-8264-46c13659ac90\2.7 there is a "hue.idb" file of 63 bytes and a hue.idb.$memlist, size 0. The idb file contains some binary data and the text "Could not import compiled module".

Any pointers?

UPDATE: I added the toolkit library as a delay load dependency and now it seems to work.
Nov 10, 2014 at 4:09 PM
For anyone else who finds this post and the solution, here's why it works:

When we analyze the library, we will import .pyd files into a running Python instance and use dir() (and equivalents) to find out what classes/functions/etc. are available. However, because we load libraries on their own, some will often raise errors if their dependencies haven't already been loaded.

Also, dependent DLLs can only be loaded if they're already on the DLL search path, which includes the directory containing the .pyd, the directory containing python.exe, and the contents of the PATH variable. A .pyd will fail to import if it can't find one of these dependencies, which is what happened here.

Making the dependent DLL delay load works because we don't actually try and run any of the code in the module, so the delay load is never triggered. If it were, the .pyd would still fail to import for the same reason (or more likely would crash the process completely).

In general, it is best to keep dependencies in the same directory as the .pyd, even if it means having multiple copies of it, as this will ensure that the correct version is always loaded.