How to "run library module as a script"?


This run configuration works, even though PyCharm shows an error in the run configuration dialog:
python-run.png

Is there a better way?
9 comments
Comment actions Permalink
Hi Stephen,

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

Readers: vote for better support for this on the tracker at: https://youtrack.jetbrains.com/issue/PY-2784 

 

0
Comment actions Permalink

Vote all you like, or just use my solution: https://github.com/amnong/misc/tree/master/pycharm_runner

Much love,
Amnon

2
Comment actions Permalink

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

0
Comment actions Permalink

@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 setup.py...

0
Comment actions Permalink

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?

0
Comment actions Permalink

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.

 

0
Comment actions Permalink

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.)

0
Comment actions Permalink

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.

0

Please sign in to leave a comment.