How to "run library module as a script"?

This run configuration works, even though PyCharm shows an error in the run configuration dialog:

Is there a better way?
Hi Stephen,

no there is no better way now. You can file a feature request in our tracker.

Readers: vote for better support for this on the tracker at: 



Vote all you like, or just use my solution:

Much love,


It works for running, but debugging doesn't stop on any breakpoints :(


@Nadavb: indeed. If I'm not mistaken the latest dev version supports running Python modules properly. Hopefully they will also support running pkg_resources entry points from


I have PyCharm 2017.3.2.

I can run a module, but when I do debug it writes: "No module named ..." Do you know what's the solution?


SOLVED. I had to add PYTHONPATH in the environment variables of the Pycharm. For some reason, I didn't have to have it during Run, but for Debug it's apparently crucial.



This now is supported by PyCharm!

When you create your `Run`, under the Configuration tab you'll notice a carrot next to `Script path:`



Click on it and select "Module name". Then you can set any args on the Parameters line...and no, you don't need to include `-m` anywhere :)


(I found the answer to this problem in this SO thread.)


Yeah and it only took 4 years for that to finally happen. 4 years for a “mature”, non-free Python IDE to be able to run Python modules instead of scripts, which is actually how Python code is supposed to be run. This is intriguing, I honestly wonder why they didn’t solve this back in 2014. I switched to another IDE btw, there are several good choices nowadays.


Please sign in to leave a comment.