简体   繁体   中英

Run python program in PyCharm with command line in console

I have a python file named "python_file.py" and I want to run it with a command line such as "python python_file.py" by typing it in the terminal, and not in the python console. I succeed one time, but when I change my working directory, it no longer works.

When I tried, it displays something like "python isn't known as a intern program, a runnable program or a command file".

And I'm using Python 3.7.

Can someone help me ?

You need to create a run/debug configuration, as explained in the official help :

  1. Click on the button left of the green arrow symbol (the green arrow might be greyed out, but that's fine):

    运行/调试配置

  2. Click on Edit Configurations .

  3. Click on the + symbol

    新配置

  4. Click on Python .

  5. On the right side, enter/activate the following:
    • Name (a string that describes your according project)
    • Single instance only (this is less complicated for you)
  6. Click on the Configuration tab.
  7. Select a type of target from the Script path/Module name
  8. Enter the path to your Python script in the according box.
  9. Select the Python interpreter (Python 3.x will be fine).
  10. In the Execution section, select either Emulate terminal in output console or Run with Python console .
  11. Apply the changes and close the dialog.
  12. Click on the button left of the green arrow symbol to run your program from the internal command line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM