1

I am trying to debug the code in corporate server, however, I need to get permission by using a sepcific command(make it short, I'll call it p). How could I debug in pycharm with a start command

p python main.py

I tried to edit configuration, but neither parameters nor interpreter options worked as I expected. Are there any settings can modify the command to start python?

The ability of showing value of variable using pdb just not satisfy my requirements.

6
  • Not sure if this would work but you may try making p python a batch file/shell script and adding that script to PyCharm as a new Python interpreter. Commented Nov 5, 2021 at 2:46
  • I tried but I just don't know how to run a batch file/shell script while using debug mode. But I think this is a good idea, I'll try it again. Commented Nov 5, 2021 at 2:57
  • What I meant was to use the batch file as the python interpreter for your project, using the Add Python Intepreter menu. Commented Nov 5, 2021 at 3:01
  • oh, I get your point! thanks a lot. I am tryng now. Commented Nov 5, 2021 at 3:09
  • It can't connect to the pycharm debugger with the batch file as python interpreter, what a pity. Commented Nov 5, 2021 at 3:35

1 Answer 1

1

This worked for me on macOS 11. Since I don't know what p in your question is, I used the time command for testing:

Created a shell script named /var/tmp/python and made it an executable (chmod +x /var/tmp/python):

#!/bin/sh
time /usr/bin/python3 "$@"

The "$@" is used to pass all command line arguments passed to /var/tmp/python to the actual /usr/bin/python3.

Then I added a new System Interpreter in PyCharm and picked /var/tmp/python as the executable.

When I debug my "Hello world" application this is the output:

/var/tmp/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 53332 --file "/var/tmp/hello_world.py"
Connected to pydev debugger (build 212.5457.59)
Hello, world!

real    0m3.091s
user    0m0.292s
sys 0m0.078s

Process finished with exit code 0

as you can see in addition to executing/debugging the application it also printed the total time passed.

Sign up to request clarification or add additional context in comments.

2 Comments

I want to run a .py code on the remote server, so I can not select "System Interpreter" as it seems to select only local interpreter. When I add a ssh interpreter, the stderr is "Could not obtain a remote socket from output"
oh! I wanted to figure out why it can not work with ssh configuration. And I reconfigured the ssh interpreter. It now worked, thanks a lot! Hope one day to be as proficient as you in python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.