2

I am using pythonnet ( https://github.com/pythonnet/pythonnet ) and have referenced a .Net library within the same solution space but it does not seem to pull in any information to use for Intellisense. In fact, VS gives an error: "Unable to resolve "ReferenceLibarary". Intellisense may be missing for this module. So how do I add intellisense to my "module"?

Even though there is an error, the script can still be run (in or out of VS). I have thorough XML already set up as there is also a sandcastle project for a chm output. Can the sandcastle project output the appropriate content that is missing?

N_tro_P
  • 673
  • 5
  • 15
  • Here is an open issue about this in GitHub: https://github.com/pythonnet/pythonnet/issues/255 – denfromufa Jun 28 '18 at 03:23
  • Thanks @denfromufa but that doesn't seem to be going anywhere and doesn't even seem to be understood by respondents. Multiple responses implied using something out of IronPython which has nothing to do with pythonnet. Sigh... I guess it is a dead end. – N_tro_P Jul 06 '18 at 15:51

2 Answers2

1

Peter Stevens answer seems fine to me. His solution uses IronPython to generate stubs. These stubs are used in turn by the CPython auto-completion mechanism, in for example, Visual Studio Code.

Let's say you have a c# dll located in c:\dev\HTL\bin\release\HTL.dll you want to access from Python and need auto-completion to help code. With IronPython installed and the ironpython-stubs module downloaded, you can do the following:

ipy -m ironstubs make HTL --path="c:\\dev\\HTL\\bin\\release\\HTL.dll" -output stubs.min

Then, as in Peter's response above, in VS Code use File | Preferences | Settings to add the full stubs.min path to "python.autoComplete.extraPaths". Having imported the target dll into your *.py file in the VS Code editor you should now be able to dot to auto-completion for the classes contained in that dll.

  • We use Pythonnet, NOT ironpython. There is a massive difference. When using ironpython you are in the CLR mimicking python. When using pythonnet you are pulling in the CLR to python. – N_tro_P Jul 29 '21 at 13:19
  • 1
    You have to use ironpython only for generating stubs, then you can continue using python and pythonnet. See https://github.com/pythonnet/pythonnet/issues/255 – johnnyontheweb Jan 13 '22 at 14:54
0

Use the ironpython-stubs module.

Make sure your dll is in sys.path, then run from ironpython ipy -m ironstubs make --output stubs.min

then set "python.autoComplete.extraPaths" to \ironpython-stubs\release\stubs.min

Works like a charm

  • The question is in the usage of pythonnet, NOT ironpython. It was both tagged and stated as such in the first line of the question. – N_tro_P Oct 15 '18 at 21:33