简体   繁体   English

如何在Pycharm中运行代码

[英]How to run code in Pycharm

If I go to "tools" and select "python console", and enter several lines of code, how do I execute this? 如果我转到“工具”并选择“ python控制台”,并输入几行代码,该如何执行? If my cursor is at the end of the script, I can just hit enter. 如果光标位于脚本的末尾,则可以按Enter键。 But how can I run the code using keyboard shortcuts if the cursor is not at the end? 但是,如果光标不在末尾,如何使用键盘快捷键运行代码? In Spyder this is done using shift+enter, but I can't figure out how to do it here. 在Spyder中,这是使用shift + enter来完成的,但是我无法在这里弄清楚该怎么做。 I've seen places say control+enter, but that doesn't work. 我见过说控制+输入的地方,但是那没用。 Thanks! 谢谢!

From Jetbrains' official documentation : PyCharm suggests several ways to run a script opened in the editor: 从Jetbrains的官方文档中 :PyCharm建议了几种方法来运行在编辑器中打开的脚本:

  • First, you can use the keyboard shortcut ⌃⇧R 首先,您可以使用键盘快捷键⌃⇧R

  • Second, you can use the context menu command (here Run Solver), invoked by right-clicking the editor background 其次,您可以使用上下文菜单命令(此处为“运行求解器”),通过右键单击编辑器背景来调用

  • Use the main menu Run | 使用主菜单运行| Run, Run | 运行,运行| Run 'Solver' 运行'Solver'
  • Finally, it is possible to run a script from the main toolbar, using the temporary run/debug configuration Solver 最后,可以使用临时运行/调试配置Solver从主工具栏运行脚本。

If you use Win 10, 64Bits. 如果您使用Win 10、64位。 Run your codes using Ctrl + Shift + F10 or simply right click on the workspace and click Run from the options. 使用Ctrl + Shift + F10来运行代码,或在工作区上右键单击并从选项中单击“运行 ”。

in mac. 在Mac中。 you can use fn+shift+f10 and happy coding with python 您可以使用fn + shift + f10和快乐的python编码

Right click on project name / select New / select Python File 右键单击项目名称/选择新建/选择Python文件

Pycharm needs to know you're running a Python file before option to run is available Pycharm需要在运行选项可用之前知道您正在运行Python文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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