# Code autocompletion on VSCode fails

**URL:** <https://discourse.slicer.org/t/code-autocompletion-on-vscode-fails/26725>\
**Category:** Development\
**Tags:** build, python, extensions\
**Created:** [December 14, 2022, 1:14pm UTC](https://discourse.slicer.org/t/code-autocompletion-on-vscode-fails/26725 "2022-12-14T13:14:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alistair\_McCutcheon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alistair_mccutcheon/32/13980_2.png) [@Alistair\_McCutcheon](https://discourse.slicer.org/u/Alistair_McCutcheon)\
**Post date:** [December 14, 2022, 1:14pm UTC](https://discourse.slicer.org/t/code-autocompletion-on-vscode-fails/26725/1 "2022-12-14T13:14:40Z")

</div>

**Problem:**  
I’m trying to use VSCode to develop a Slicer extension. This is my first time using Slicer. I am trying to set up my development environment such that the code has typical autocomplete functions. I am using Ubuntu 22.04.1 LTS and VSCode version 1.74.0 5235c6bb189b60b01b1f49062f4ffa42384f8c91 x64. My Slicer version is 5.2.1-linux-amd64

**Similar Topics:**  
Here are the other topics I’ve looked at, but neither solved my issue.

> [@Autocomplete code lines for slicer in an IDE?](https://discourse.slicer.org/t/autocomplete-code-lines-for-slicer-in-an-ide/7390):
>
> new to slicer development, saw this tutorial and they seem to use an IDE that supports autocompleting statements unique to slicer as in the python interactor: what IDE could i use for that feature ( or how to add slicer API support to IDEs like pycharm?) Thanks for your help.

[Developing Slicer modules in Visual Studio / Visual Studio Code?](https://discourse.slicer.org/t/developing-slicer-modules-in-visual-studio-visual-studio-code/9496) (slightly out of date as pythonPath is not part of the settings.json file anymore).

**What I’ve tried:**  
I’ve selected the Python contained in Slicer.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/f/ff52cf4b9db0fb9733056801030ef858716191c7.png)

I then went into the integrated python console of the slicer gui and ran:  
slicer.util.pip\_install(‘pylint rope autopep8’)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/5/e54fc096152df9b331efac14caeae177c1b0b87f.png)

My workspace settings.json file in .vscode is as follows. I have verified that this file is in the correct location.

```auto
{
    "python.autoComplete.extraPaths": [
        "/opt/Slicer-5.2.1-linux-amd64/",
        "/opt/Slicer-5.2.1-linux-amd64/lib/",
        "/opt/Slicer-5.2.1-linux-amd64/lib/Python",
        "/opt/Slicer-5.2.1-linux-amd64/lib/QtPlugins",
        "/opt/Slicer-5.2.1-linux-amd64/lib/Slicer-5.2",
        "/opt/Slicer-5.2.1-linux-amd64/bin",
    ],
    "python.linting.pylintPath": "/opt/Slicer-5.2.1-linux-amd64/lib/Python/bin/pylint",
    "python.analysis.extraPaths": [
        "/opt/Slicer-5.2.1-linux-amd64/",
        "/opt/Slicer-5.2.1-linux-amd64/lib/",
        "/opt/Slicer-5.2.1-linux-amd64/lib/Python",
        "/opt/Slicer-5.2.1-linux-amd64/lib/QtPlugins",
        "/opt/Slicer-5.2.1-linux-amd64/lib/Slicer-5.2",
        "/opt/Slicer-5.2.1-linux-amd64/bin"
    ],
    "python.linting.enabled": true,
    "python.formatting.autopep8Path": "/opt/Slicer-5.2.1-linux-amd64/lib/Python/bin/autopep8",
}

```

After doing this, I would expect to be able to have VSCode autocomplete/provide suggestions on modules etc. However:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/4/6418f1e128f2abd938b5abb6f2d9ef904b2854ea.png)

I do have the suggestions when importing however, suggesting vscode is indeed pointing to the correct Python launcher:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/6/f642416183f871640334479f7caf6affb514b8a6.png)

I have also tried copying the above settings.json file to the user settings.json file, but to no avail.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [July 19, 2023, 6:23pm UTC](https://discourse.slicer.org/t/code-autocompletion-on-vscode-fails/26725/2 "2023-07-19T18:23:44Z")

</div>

Has anyone gotten further than this? I have followed the same path of trying to get this to work and gotten stuck at the same place… `slicer.` lists a few things as autocomplete options, but not things like `slicer.util` . However, I can do `from slicer import ` and get `util` as a suggestion, and then I can get many `util.` method autocompletion settings. However, if I do `slicer.util.` I get no autocompletion options. I don’t understand this… shouldn’t `slicer.util.` be the same as `util.` after `from slicer import util`? I’m not sure why one successfully autocompletes but the other doesn’t.

I understand from a previous thread that wrapped C++ code might be a problem as well as things which might be more dynamically constructed like `mrmlScene`, but I’d love to get autocompletion working at least for all the purely python and static components like `util`. Any help out there? I did try adding `"C:\\Users\\mikeb\\AppData\\Local\\NA-MIC\\Slicer 5.2.1\\bin\\Python\\slicer"` (the home of `util.py`) to the VSCode `settings.json` list of extra `python.autoComplete.extraPaths`, but it didn’t seem to help.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 21, 2023, 5:11pm UTC](https://discourse.slicer.org/t/code-autocompletion-on-vscode-fails/26725/3 "2023-07-21T17:11:44Z")

</div>

@jcfr there are some Slicer pull requests with related changes. Could @mikebind test/work ok those?

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [July 21, 2023, 6:06pm UTC](https://discourse.slicer.org/t/code-autocompletion-on-vscode-fails/26725/4 "2023-07-21T18:06:51Z")

</div>

To get an idea of the remaining work, see [Improve auto-completion support · Issue #6690 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/issues/6690).

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [July 21, 2023, 10:37pm UTC](https://discourse.slicer.org/t/code-autocompletion-on-vscode-fails/26725/5 "2023-07-21T22:37:44Z")

</div>

Thanks for the link @jcfr. I would be happy to try to test things on my system. Unfortunately, looking through the changes and remaining work, I doubt I would be capable of contributing in a meaningful way to helping move things forward. While I would consider myself fairly comfortable developing scripted python modules in Slicer, at this point, the build system and even the C++ level of Slicer code are generally hard for me to follow. I can follow directions and be a naive user checking if PR’s work on my system though!
