I recently switched from using PyCharm (which i love, honestly) to Visual Studio Code. Mainly I wanted to take the leap back into more open source tools again, rather than paid IDEs that not everyone may have access to.

In a former life I was a pretty serious .NET developer and mostly enjoyed the later editions of Visual Studio. I’ve used VS Code for small things here and there and enjoyed it, but never really put it through the test of using it for a full project life cycle.

Setting up Python was pretty easy, it prompted my to install a few extensions and then eventually I added the “Python Extension Pack” which covered just about all my basic needs

I’ve converted to pipenv earlier this year and so my next step was to create a virtual env the normal way. I went to the terminal tab in VS Code and simply ran:

pipenv --python 3.6
pipenv install

So far so good. What I ran into pretty quickly was VS Code not picking up the virtualenv by default. I fixed that (solution below) but then ran into a bunch of other issues with autocomplete and “Go to definition/symbol” not being able to find both django packages and packages from my local project.

The fix wasn’t immediately obvious, but after digging through github issues I manage to find 3 lines that I added to my local settings.json file that fixed everything:

{
    "python.venvPath": "/Users/me/.local/share/virtualenvs/",
    "python.pythonPath": "/Users/me/.local/share/virtualenvs/ENV-NAME/bin/python",
    "python.jediEnabled": true,
}

After adding these and restart VS Code, I was finally able to navigate around the project, get autocomplete working, and easily navigate to definitions through out my project.

Pro tip: An easy way to figure out your python Path is to type the following in the terminal where there’s an active pipenv virtual env:

pipenv --py

Users/me/.local/share/virtualenvs/ENV-NAME/bin/python

# # # # #

October 1, 2018