Python3.7最新版でVSCodeの定義へ移動(Go to Definition)が使えなくなった場合の対処法

Kanta Asada
Sep 1, 2018 · 2 min read

参照: https://github.com/DonJayamanne/pythonVSCode/issues/601#issuecomment-269075729

Python3.7にしたところコードジャンプが使えなくなったので、解決策をメモ。

当時pipenvを導入とpython3.7にしたのが同時だったので、原因が掴めかねていましたが、VSCodeの「ヘルプ→開発者ツールの切り替え」で以下のエラーが出ていることが分かりました。

FileNotFoundError: [Errno 2] No such file or directory: 'preview/jedi/parser/grammar3.7.txt'

jediの3.7用grammarがないためでした。jediはまだ3.7に対応していないようなので、とりあえずは3.6のgrammerをコピーすることにします。

$ cd ~/.vscode/extensions/donjayamanne.python-0.7.0/pythonFiles/preview/jedi/parser$ cp grammar3.6.txt grammar3.7.txt

以上でコードジャンプが使えるようになります。

と思いましたが、原因は他にありました!(上の作業は不要でした)

原因はVSCode Python拡張機能の古いバージョンが残っていたためでした。

rm -rf ~/.vscode/extensionsdonjayamanne.python-0.7.0

これで直りました。

余談:pipenvでPIPENV_VENV_IN_PROJECT=1を有効にしたら、プロジェクト内でライブラリのソースにジャンプできて便利!
(ユーザ設定に”python.venvPath”: “.venv”,を追記して、cmd+shift+Pで「Python: インタプリターを選択」→ ./.venv/bin/pythonを選択する必要あり)

    Kanta Asada

    Written by

    Mobile & Web Developer in Japan.

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade