Visual Studio Code is the first code editor, and first cross-platform development tool - supporting OSX, Linux, and Windows - in the Visual Studio family. At its heart, Visual Studio Code features a powerful, fast code editor great for day-to-day use. And in the course Visual Studio Development on a Mac, you'll witness the impact a virtual machine running Windows and Visual Studio has on its host, the Mac OS X. This smooth performance is in the details of Apple's hardware and the cleverness of the virtual machine software.
- Visual Studio Code For Mac
- Visual Studio Code For Typescript
- Visual Studio Mac Download
- Download Visual Studio Code For Linux
- Visual Studio Code For Raspberry Pi
- Use Visual Studio, a fully-featured and extensible IDE on Windows. Or, use Visual Studio for Mac, a rich IDE for macOS. Both offer UI designers, efficient code editing, debugging and publishing tools, and more.
- In this short article I'm going to give you an overview of Visual Studio Code, a free and open source IDE for Windows, Mac OS X and Linux, from Microsoft.This IDE is highly configurable and extensible with plugins, including a very good one for Python.
- Using Visual Studio Code and Building and Debugging with C++ on Mac OS X Saturday, August 6th, 2016. By Michael Suodenjoki, August 2016. I wanted to play with and test Visual Studio Code's (VSCode) features for doing C++ development on the Mac platform.
- Visual Studio for Mac enables the creation of.NET Core solutions, providing the back-end services to your client solutions. Code, debug, and test these cloud services simultaneously with your client solutions for increased productivity.
2017-05-01T01:23:18Z
Visual Studio Code For Mac
In this short article I'm going to give you an overview of Visual Studio Code, a free and open source IDE for Windows, Mac OS X and Linux, from Microsoft. This IDE is highly configurable and extensible with plugins, including a very good one for Python.
Click on this and any of the following screenshots to see a larger image.
Installation
You can head over to the Visual Studio Code home page to download installers for Windows, Mac OS X and Linux. For this article's images and animations I used the Mac OS X version.
Once you have it installed, you would probably want to add the code
command to your path, so that you can start an instance from the command line. You can do this by hand according to your operating system, or you can bring up the slick command palette (Ctrl+Shift+P
on Windows/Linux, Cmd+Shift+P
on Mac) and let the program register itself with the system path:
By default, vscode comes with JavaScript support. You can install the python plugin from the command line as follows:
Visual Studio Code For Typescript
Or if you prefer to do it within the tool, once again you can do so from the command palette with a couple of mouse clicks:
The Python extension requires that you install the exuberant ctags tool, which helps with the symbol extraction from source code files. On the Mac, you can install it with homebrew (brew install ctags
), on Ubuntu Linux with apt-get (sudo apt-get install exuberant-ctags
). On Windows you will need to download an executable and install it somewhere on your path.
Starting a new project
To start a new project, what I find the most convenient is to create my project in the command line however I like, including a virtual environment with my preferred python version. Then, I can start Visual Studio Code from the root directory of my project with this simple command:
Note the dot, given as an argument, so that a new project is created on the current directory.
There is an extra step that isn't always necessary, which is to select the Python interpreter to use. Normally the interpreter from the virtual environment will be picked up automatically, but I've found that this does not always work. So to be on the safe side, I got used to selecting the interpreter when I open the IDE for the first time on a project. This is done from (you guessed) the command palette:
Configuration
There isn't much to configure, as most sensible options for Python development are enabled by default. Visual Studio Code uses JSON files for configuration. There are two files, the user settings file, for the global configuration that applies to all projects, and the workspace settings file, for the options specific to the project.
Many configuration items can be set interactively, but all the interactive method does is add the setting to the proper JSON file. In the above section I showed you how you can select which Python interpreter to use for a project using the command palette, for example.That translates to the following changes in the workspace settings file:
Editing the user and workspace config files is a pleasure, because you get popups as you type with help messages.
Intellisense
Speaking of 'as-you-type' coding assistance, Microsoft calls that Intellisense. This is also enabled for Python, and works for symbols in the standard library and also for your own code (provided you installed ctags, as I indicated above):
Code Linting
Another useful feature that is also enabled by default is code linting. Whenever you save a file, Visual Studio Code runs pylint and shows a report of all the problems that were found, both as a list, and visually with color squiggles in the code. If pylint is not installed in your virtual environment, Visual Studio Code offers to install it for you.
If you find the output from pylint too detailed (sometimes I do), you can use flake8 instead. You can also enable both if you want. To make these changes, you just edit the JSON config files.
Code Formatting
Visual Studio Code tries to format the code nicely as you type it, but it does not do a perfect job at it. In particular, it is unable to indent multi-line lists of function arguments in the pep8 style (there is an open issue about this on the Python plugin repository). In any case, I've found that it is a lot easier to not worry too much about formatting while typing, and then let autopep8 format your code when you save it.
Note that autopep8 formatting on save is not enabled by default, you need to add this option to the configuration. This is what I added to the config file:
If you add this to the user settings file, then all your projects will have an autopep8 pass when you save a Python file.
Debugger
There is also an integrated debugger, with support for line-by-line execution, breakpoints, watches, call stack and popups for variables.
Unit Tests
Visual Studio Mac Download
Visual Studio Code also has a unit test runner that displays these cool overlays above each test that allow you to run or debug that one test. It can also run the entire unit test suite, all the tests in a module, or only the tests that failed in the previous run, if you prefer.
Source Control
I don't really use the source control options much, since I prefer to do all of that from the command line. But if you are more of a visual type, Visual Studio Code allows you to run several git operations directly from the interface. Occasionally I have found the graphical diff view useful, so at least for that I like to have source control in the tool. You can see a screenshot of this view at the top of this article.
Final Words
I hope you found this walkthrough useful. If you liked what you saw, I encourage you to give Visual Studio Code a try. I have been using it regularly for the last couple of months for a variety of projects, both personal and from work, and have found it fairly stable. I think it is not quite as polished as PyCharm, but on the other side, it seems lighter and faster, so overall I'm pretty happy with it.
Hello, and thank you for visiting my blog! If you enjoyed this article, please consider supporting my work on this blog on Patreon!
20 comments
#1Leandro E. Colombo Vi単a said 2017-05-01T02:50:55Z
Great walkthrough Miguel! Pretty straight forward on several key issues un Python development. I'm a PyCharm user, and I'm very happy with it. Even thought sometimes It's a little big heavy and slow, as you had mentioned... But I'm looking something to include in my teaching. I believe that an IDE for a 101 introduction to programming It's too much Information for students to absorbe. I've been using Atom with my students but I'm not very pleased with UX in Python Development, maybe I'll give it a shot with VS Code. Thanks!
#2Sanjayshr said 2017-05-01T19:51:02Z
It's been a year now I using Vim it's pretty faster but lags when it comes to plugins, I just tried VS Code its just awesome :), Waiting for Part 2 of 'Flask Mega-Tutorial'. Thanks!
#3Sts said 2017-05-01T22:44:05Z
Does it have support for more data science workflows with lots of plotting and notebooks etc?
#4Miguel Grinberg said 2017-05-02T02:26:50Z
#5Pouya said 2017-05-05T00:36:10Z
It's worth mentioning that if you are after a full-fledged IDE (similar to pycharm) Microsoft has PTVS (Python Tools for Visual Studio) to offer.
#6Tony said 2017-05-05T02:59:47Z
@Sts -- The VSCode python plugin formerly had support for Jupyter notebooks (including plot visualization), but the author moved it to a separate plugin. https://marketplace.visualstudio.com/items?itemName=donjayamanne.jupyter
#7Miguel Grinberg said 2017-05-05T05:59:41Z
@Pouya: I don't disagree that PTVS is a good IDE, but Visual Studio Code is a full-fledged IDE as well. Also PTVS runs only on Windows.
#8Simon Wolf said 2017-05-11T11:17:27Z
Regarding the Linting section, if you want some more information about enabling and disabling linters then I found this wiki page useful: https://github.com/DonJayamanne/pythonVSCode/wiki/Linting
#9erhuabushuo said 2017-05-12T03:47:57Z
Hi, Miguel. is there any way to generate docsting automatically.
#10Miguel Grinberg said 2017-05-12T05:07:08Z
@erhuabushuo: I don't think so. But you can create your own module or function templates exactly as you like them and store them as user snippets that you can insert when you need a new element.
#11Allyn H said 2017-05-16T15:14:30Z
Hi Miguel / all, I've just downloaded VS code as per this blog post and I'm finding it great. Are tehre any other plugins that you'd recommend for either web dev or Python?
#12Kuldeep said 2017-07-21T21:10:50Z
I am new to both Python and VS Code and I struggling to find a way to add Python modules to VS code. Can you pls show the steps/cmds to add any Python modules to VSCode project.
#13Miguel Grinberg said 2017-07-22T00:20:46Z
@Kuldeep: There is nothing special about adding Python modules to a project. As long as the project you open has Python files, they should be shown by vscode. Make sure you install the Python plugin to have a much better experience with these Python source files, though.
#14T said 2017-08-15T23:27:24Z
My favourite editor! Works great with Raspberry Pi when using cyberduck + SFTP to edit the python code.
#15Dan Griscom said 2017-10-11T20:13:44Z
Your Exuberant Ctags link is misspelled (no 'h'), and broken (you have to use 'http' rather than 'https'). The correct link is http://ctags.sourceforge.net/ .
#16Miguel Grinberg said 2017-10-11T21:39:04Z
#17Yuri said 2017-10-15T16:36:17Z
Miguel have you ever tried something that works for jinja2?
#18Miguel Grinberg said 2017-10-15T16:59:33Z
@Yuri: What do you mean? You can edit Jinja2 templates with code just fine, I do it all the time.
#19Tristan Trouwen said 2017-11-05T14:37:05Z
Since the python extension uses ptvsd instead of pydevd for debugging it is extremely slow for some larger projects. A simple flask server can take up to two minutes to load. Have you got an alternative debugging solution?
#20Miguel Grinberg said 2017-11-05T14:40:31Z
@Tristan: The vscode debugger hasn't been slow for me at all. Two minutes? I have it up and read in a couple of seconds.
Leave a Comment
Visual Studio Code is an excellent developer tool for PowerShell projects. However, regardless of which type of project you’re developing (C#, Node.js, Python, etc.), you can benefit from changing your default shell to the powerful, object-oriented PowerShell shell. Now, you may not want to change your default shell for the entire operating system. VSCode thankfully exposes a configuration option that allows you to change the default shell only for the VSCode Integrated Terminal. This won’t affect the default shell for your host operating system.
Download Visual Studio Code For Linux
To change your default shell for VSCode to PowerShell Core, simply:
- Install Visual Studio Code
- Install PowerShell Core
- Hit CMD + , (Mac OS X) to open your User Settings, or search for it via the Command Palette (F1 key)
- Add the terminal.integrated.shell.osx option to your JSON configuration
- Set the value of the option to /usr/local/bin/powershell
If PowerShell Core is installed to a different location, you can use the which powershell command from a Bash or ZSH shell to locate the binary. Then, populate the path accordingly in your VSCode User Settings configuration. If you’re using Linux or Windows, instead of Mac OS X, then you’ll simply replace the terminal.integrated.shell.osx setting with terminal.integrated.shell.linux or terminal.integrated.shell.windows. VSCode’s User Settings supports JSON schema Intellisense, so as you type the setting, it will auto-complete for you.
Here’s what my current User Settings file looks like.
UPDATE (2018-03-18): Make sure you use the new binary name /usr/local/bin/pwsh instead of /usr/local/bin/powershell! Thanks to Zach Knight for calling this out. I’ve updated the screenshot below.
As you can see, now that I’ve changed my default shell, hitting CTRL + ` (backtick) results in a shiny new PowerShell instance directly inside of VSCode!
Visual Studio Code For Raspberry Pi
Follow me on Twitter and check out my YouTube videos.