pycharm 2020.2 running external tools installed in WSL2?

I'm aware there is no venv support in wsl2, however I am able to select a Python interpreter installed in wsl2.

However, I don't seem to be able to select "External Tools" in WSL2 - despite them running on the Python interpreter I can select?

Examples would be black or flake8 executables co-located in the same bin directory as my interpreter.

Can you explain how to setup such tools, installed inside WSL2, from native Windows PyCharm Professional?

If I try to reference the tool directly using the WSL file share this unsurprisingly fails, but I thought there might be another way to do this given the underlying use of the Python interpreter?

12:41 Error running 'Black': Cannot run program "\\wsl$\Ubuntu-18.04\home\pob\venvs\my-repo\bin\black" (in directory "C:\Users\Pob\PyCharmProjects\my-repo"): CreateProcess error=193, %1 is not a valid Win32 application

 

EDIT

A poor solution to this, if the tools you need to run can be called as python modules (like Black above) is to use a Run Configuration rather than an External Tool to configure it.  This works, but due to lack of macro expansion in the Run Configuration - it is fairly limited.

 

 

It's still a valid question how to properly integrate tools into WSL2.

2
2 comments
Avatar
Permanently deleted user

It could be done with `wsl LINUXCOMMAND` and relative file paths. Example for flake 8.

Name: Flake 8 (WSL,venv)
Program: wsl
Arguments: /home/USERNAME/VENV_ROOT/bin/flake8 $/FilePathRelativeToProjectRoot$
Working directory: $ProjectFileDir$
Output patterns: $FILE_PATH$\:$LINE$\:$COLUMN$\:.*⏎$FILE_PATH$\:$LINE$\:.*

Or using "ubuntu run" command

4

Thanks to the post above, I got this working (i.e., send to emacs via a Windows Terminal) using IDEA like this:

Tools > External Tools > Add > Emacs

Program: wt
Arguments: wsl --distribution Ubuntu /usr/bin/emacs $(wslpath '$FilePath$')
Working directory: $ProjectFileDir$

Notes:
wt = windows terminal
wslpath translates the FilePath to a POSIX path for emacs

0

Please sign in to leave a comment.