Karl Jan Clinckspoor

My personal site

Publications

Education

Blog Posts and Tags

View My GitHub Profile

11 April 2021

PyCharm, WSL and external tools

by Karl Jan Clinckspoor

As I alluded to in a previous post, I like using Windows Subsystem for Linux (WSL) and Python. I also enjoy using PyCharm to write more structured programs (for exploratory data analysis, it’s Jupyter Notebooks all the way), more than VSCode, for PyCharm, despite being much more of a resource hog, it has better support for fetching documentation (IMO), has superior debugging and a better interface to set new ways to run your tests (I like clicking and not editing JSON manually, OK?). However, VSCode has one thing that’s much better than PyCharm, which is its handling of WSL.

I like to apply code formatting, and the black code formatter is one of my favorites. Setting it to run in PyCharm is relatively painless, provided you follow their instructions, but if you do that, it won’t work with WSL. And, to complicate things, I have it installed in a specific conda environment in a pyenv environment. What a mess.

Nevertheless, I got it working. Go to Settings > Tools > External Tools, add a new entry to black and then add this:

To run this automatically every time a file is saved, you can use the tutorial provided in the documentation, and use the same program and arguments I provided.

If this breaks when I’m doing something more complicated, I’ll update this.

tags: python - wsl