Comparing PyCharm and VS Code
I use both PyCharm and VS Code regularly and have now sufficient experience with them to compare them. For pure Python development I like PyCharm a little more, for full-stack development I like VS Code more. For my use cases, they are not that far apart.
Before starting my full-time job, I used Vim for my coding. That worked somewhat well. At my job I got a license for JetBrains CLion, the C++ IDE from the IntelliJ family. That was quite a change for me, now I had all these advanced features that I didn't have with Vim and started to be more productive.
For my personal things I used VS Code because it is free and supports many languages with a single IDE. It feels faster than CLion. Eventually I realized that there is the PyCharm Community Edition that is free to use. So for Python I actually have two sensible options.
Let's go through a couple of tasks that show how they work. This is a screenshot of VS Code with my project open. You can see the editor in the center, the files on the left and the structure on the right.
With PyCharm I have the same window, just details are different.
Both pack a lot of information on the screen, just how I like it for an IDE.
Missing function
I've then started programming and called a function that didn't exist at the time. In VS Code it will tell me that this function is not defined:
I can click on the “quick fix” text and it will open a pop-up:
There I'm offered to search for this symbol elsewhere or to ignore it. Hmm.
In PyCharm I get the same message:
But in the quick-fix menu there are really helpful options. It can create a new function for that. Or it can add it as a parameter to the current function. And it offers to ignore it.
Here I find PyCharm more helpful.
Missing import
Next I programmed something where I used pathlib
but didn't import it yet. In VS Code it tells me that this is undefined.
In the quick fix menu I can add the import pathlib
.
In PyCharm it shows the same issue:
In the quick fix menu of PyCharm I also have the option to import it only locally or take it as a parameter.
So again, PyCharm has more options here.
Expanding methods
I have this object secret_file
which is an instance of pathlib.Path
and as such has a bunch of methods and attributes. When I type the .
, VS Code gives me a list of these. It has them alphabetically sorted and displays this violet cube for methods and the wrench for attributes.
Compare this to the same thing in PyCharm. There the order seems to be ordered by relevance, perhaps trained on various open source codes. It tells me what the methods return and what arguments they take. The symbols also seem more sensible.
This is again more powerful.
Function argument hints
Now that I've settled for the exists
method, VS Code shows some help for that:
The return value is there, but apparently there are no arguments.
In comparison, PyCharm shows more documentation and has more arguments than VS Code shows:
Here it becomes pretty interesting! The IDE is configured to use Python 3.9 and if one takes a look at the Pathlib documentation for Python 3.9 one can see that it doesn't take any arguments. So PyCharm eagerly fetches the latest version of that documentation although that is not applicable here. VS Code does the right thing.
If I switch VS Code to use Python 3.12, it also correctly shows the arguments that have been added:
This makes it seem that VS Code uses the documentation for the correct Python version whereas PyCharm just takes the latest one.
Argument completion
Next we need to fill in the arguments. PyCharm is unique because shows the arguments as a tooltip already.
When pressing Control+Space, VS Code opens a seemingly useless menu. But that's because it knows that there are no arguments with Python 3.9.
With Python 3.12, it shows the one named argument:
PyCharm however also suggests things that could be put in there, like the local variables or modules that I have available there. That is only somewhat helpful. One thing that I do like is that it tries to fuzzy-match the argument names to my local variables and therefore often suggests sensible things.
Ambiguous module import
There are various modules called json
, so it is not clear which one to import. VS Code first tells me about the missing import:
And then it suggests multiple ones, but the most relevant is not on top.
PyCharm gives the same issue:
But then it asks me to choose where to import from. Curiously it doesn't have flask.json
but other ones.
Slightly in favor of PyCharm.
Documentation pop-up
For json.dump
I always need to look up whether the object or the file pointer goes first. In VS Code I get this documentation which tells me all I need:
PyCharm also shows some of the text from the documentation.
But I can also press Control+P and get this little tooltip:
When asking for autocompletion with Control+Space, I get this. It makes sense, because for the object I could put in all sort of things.
When one is not editing a function, it can also shows the names of the arguments such that you know that you're doing the right thing.
Version control diff
After doing changes, one can take a look at the difference. In VS Code it looks like this:
In PyCharm you have a similar view, the UI looks a bit more fancy.
Features not included in the community edition
VS Code is completely free to use and there are various free add-ons for every programming or configuration language that I have used so far. For instance the Jinja templates can be edited nicely:
PyCharm can do that too, but this is a feature reserved for their paid tier. With the free Community Edition one cannot get syntax highlighting and indentation for that:
So here I need to decide: Buy PyCharm Professional for around 120 EUR/year, use VS Code for my hobby projects or use a mix of both? So far I have been sufficiently happy with VS Code for hobby projects that I don't need PyCharm Professional for my personal projects.
The other thing that VS Code offers for free are (Jupyter) notebooks. The UI is vastly better than the one in the browser. PyCharm has these only in the Professional edition.
Finding symbols
One of the nice features of an IDE is that they're generally aware of your code. I have this class ActivityRepository
that I use as repository
throughout the code. When I want to fuzzy search for that class, PyCharm lets me search for that using it's “find anything” functionality with Shift Shift:
You can see that it found the class as the first entry and then has usages down below.
VS Code doesn't search fuzzy. With Control+T it only shows me the instances:
When I type in ActivityRepository
, it does find the correct thing for me.
Showing usages
For a class or function it is helpful so jump to the definition. Both do that fine. Finding usages is something that both also do nicely.
VS Code has this larger pop-up that shows the definitions and one can expand them a bit. One can also scroll through the whole other code file in the pop-up:
PyCharm does that a bit differently. There we have a pop-up that only shows the code locations:
Clicking on those brings us to the other file.
But there is another option, one can show the usages in the bottom tool window:
And there we can go through all the usages on the left and see the whole code file on the right.
In the end both offer the same usage functionality and I cannot say which one I like better.
Project setup
Setting up a run-of-the-mill Python project with Poetry is super easy with VS Code. I just run poetry run code .
in the project directory and VS Code directly picks up the correct Python interpreter from the environment variable. That's it and I love it.
With PyCharm it is not as simple as that. It will ignore the environment variable, even if I do poetry run pycharm-community .
. Then it will tell me that no Python interpreter is configured.
Then you go into the settings menu to pick a Python interpreter. In the following screenshot it is already configured, but at first there will be no interpreter to select.
One has to select “add interpreter” and then another menu opens:
There one can select what kind. It seems to support Poetry, but a year ago that was broken. Therefore I only used the “virtualenv environment” and manually select the interpreter:
It seems that Poetry support got fixed by now. Then one can just select Poetry and the Python version and it will work.
This is not that big of a deal as one only needs to do that once for the project.
Refactorings
PyCharm has powerful refactorings available. I can select a class and it shows me a list of possible refactorings:
Also functions have their own options. There is a new option to change the signature.
I can then change the order of the arguments, rename them and so on. This will be propagated to the call sites. It seems to remove the type annotations, though.
Variables can also be refactored. I can inline them, for instance.
All symbols can be moved, there is a dialog that lets me select which symbols to move such that I can bulk move.
VS Code doesn't really have any option besides moving code when I click on refactorings for classes or methods:
And the target selection isn't as helpful as the one from PyCharm.
Both have good support for renaming things. PyCharm suggests good alternative names like all-caps, camel-case.
Conclusion
For writing just Python code, I prefer PyCharm over VS Code. It has more features, refactorings, powerful fuzzy search and slightly more helpful code completion and tooltips. The free Community Edition suits my needs pretty well.
Only when it comes to projects with multiple programming languages I find that the free version of PyCharm becomes inferior to VS Code that has less advanced but more broad support. With VS Code I can switch between Python, Python Notebooks, Jinja and JavaScript with ease. With PyCharm Community Edition I am limited and would need to purchase the Professional edition.
VS Code feels a bit snappier at times. This is somewhat surprising because VS Code is written with JavaScript whereas PyCharm is developed in Java. So it might seem that Java should be faster than JavaScript. I think that PyCharm does a lot of heavy indexing at startup and therefore takes quite a while before it is fully there. But once it is loaded, the wealth of features and code insights explain why it sometimes needs a little longer than VS Code.
Depending on the need for features, both are good IDEs. If somebody is just starting out with programming, both are just fine. At some later stage one can take a look at the other one and realize that a lot of concepts are very similar. So it doesn't matter to much which one you start out with.