22

How do I add a custom python module to the Visual Studio IntelliSense code completion tool?

Situation: I am working on a python module that references another module that I have saved in /myPython/foo.py.

If I start to type foo.someDef I would like IntelliSense to recognize I am accessing that module and suggest a code completion.

CompSci-PVT
  • 1,303
  • 2
  • 10
  • 23

1 Answers1

14

Visual Studio's Intellisense will recognize custom Python modules after they have been properly placed in the "site-packages" folder under the "Lib" folder in Python's directory.

For example: /Python27/Lib/site-packages/myPython

Inside of the folder "myPython", put a plain text file called "__init__.py". Otherwise Intellisense will not recognize your package.

You may also have to click the "Refresh DB" under the Python Environments tab.

Menu to Python ToolsPython Environments

CompSci-PVT
  • 1,303
  • 2
  • 10
  • 23
  • 1
    Where is "Refresh DB" in VS2013? That seems to be important because I checked all site-packages folders and they contained "\_\_init\__.py" files. – stifin Jan 04 '16 at 13:30
  • 7
    To access the "Refresh DB" button, switch the dropdown selection from "Overview" or "pip" to "IntelliSense". – mars Mar 29 '16 at 15:34
  • Anyone else new to the Python Party might find this useful: http://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/quickstart.html You can also find a bit about it in Mark Lutz's Learning Python. – JGFMK May 11 '18 at 15:08
  • The database refresh python environment stucks in VS 2017. There will be a correction in 15.7 as Steve Dower announced https://developercommunity.visualstudio.com/content/problem/222340/python-intellisense-database-refresh-frozen.html Steve Dower [MSFT] · 26 03 2018 um 16:41 0 But that does not work either –  Jan 27 '19 at 09:18
  • As Thomas Kadlec reported it does not work for 15.8. I have 15.9 and it stucks. Microsoft set it to solved. –  Jan 27 '19 at 09:30
  • In case where you can't or don't want to move your modules, you can add the path to the module to the Search Paths in the Solution Explorer. This also allows you to step into the module's code correctly. – Stranger1399 Jun 25 '19 at 09:58