LoginSignup
33
34

More than 3 years have passed since last update.

Enable python intellisense for Visual Studio Code.

Last updated at Posted at 2019-03-15

前置き

お久しぶりですnullです。
本業が忙しく何もできていない状況でしたが、ようやく落ち着いて来たので時間があるときに
Visual Studio CodeでPython使って何かしてたりします。

しかしコーディングする時に便利なIntelliSenseがPythonで有効にならない問題が発生してかなり困っていました。
公式ドキュメントのtroubleshooting_intellisenseを試しても解決しなかったので、他に方法ないか調べたところ
GitHubのissuesでこれを試してみてとあったので試したところIntelliSenseが有効化されました。

今回はそんなIntelliSenseを有効化する手順をまとめました。

Visual Studio CodeでPythonのIntelliSenseを有効化

本記事ではVisual Studio Codeの拡張機能である、
Microsoft製PythonのIntelliSenseを有効化する手順となります。

実行環境

OS
- Windows10(64bit)

Application
- Visual Studio Code 1.32.3
- Python 3.7.2(32 bit)

Visual Studio Code Extension
- Python(ms-python.python)

Python Module
- linter用にpylintをpip installで入れている以外は初期状態

pip list
Package           Version
----------------- -------
astroid           2.2.5
colorama          0.4.1
isort             4.3.15
lazy-object-proxy 1.3.1
mccabe            0.6.1
pip               18.1
pylint            2.3.1
setuptools        40.6.2
six               1.12.0
typed-ast         1.3.1
wrapt             1.11.1

問題のIntelliSenseが有効にならない状態

multiprocessingを使用して別プロセスで関数を使用しようとしています。
この時はstart関数をIntelliSenseで出そうとしてます。

IntelliSenseを起動すると有効になっているように見えますが、
実はファイル内の文字列が羅列されているだけでstart関数やProcessで利用できる関数が出てきません。

2019-03-16_00h26_20.png

これを解決してstart関数が出る状態します。

有効化する手順

方法1

.vscode ディレクトリに保存されるsettings.json を使用します。
以下のようにsettings.jsonに設定を行い保存します。

{
    "python.pythonPath": "C:\\Program Files (x86)\\Python37-32\\python.exe",
    "python.jediEnabled": false
}

※ python.pythonPathはSelectorで自動的に設定されたもので無視しても構いません

するとVisual Studio CodeがReloadしろとインフォメーションを出してくるのでリロードします。
2019-03-16_00h33_00.png

方法2

Visual Studio Codeの基本設定からpython.jediEnabledを変更します。

設定を選択します。
2019-03-16_00h37_24.png

python.jediEnabledを検索して、チェックを外します。
2019-03-16_00h38_14.png

するとVisual Studio CodeがReloadしろとインフォメーションを出してくるのでリロードします。
2019-03-16_00h40_17.png

リロード

リロードを行い、Pythonの出力を確認すると以下のようにMicrosoft Python Language server.が起動します。
無い場合は自動的にインストールされます。

2019-03-16_00h42_02.png

完了

お疲れ様でした。
これでPythonでIntelliSenseが有効になりました。
Ctrl+SpaceなどでIntelliSenseを起動してみた状態。

2019-03-16_00h46_05.png

蛇足

Microsoft Python Language serverが何者なのか
こいつは元々Visual StudioのPythonのインテリセンスエンジンとして使用されていました。

それが去年の夏頃にPython拡張機能がアップデートされて、Visual Studio Codeにも使用できるようになりました。
Introducing the Python Language Server

33
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
34