pycharm代码运行程序_与代码设置直接运行程序

本文介绍了如何在PyCharm中设置代码,以便直接运行Python程序,参考自一篇Medium文章。
摘要由CSDN通过智能技术生成

pycharm代码运行程序

I usually use Jetbrein’s product for development work as a project. But it is not efficient to use those IDEs for a small project or single file. Because those IDEs are very heavy and bit slow. For this, I need to think for else. I can solve this problem using VS Code. As I need to install a compiler/interpreter, a small setup can provide me this.

我通常将Jetbrein的产品用作项目的开发工作。 但是,将这些IDE用于小型项目或单个文件的效率不高。 因为这些IDE非常繁琐,而且速度很慢。 为此,我需要考虑一下。 我可以使用VS Code解决此问题。 当我需要安装编译器/解释器时,一个小的设置就可以为我提供此服务。

先决条件 (Prerequisite)

  • Basic knowledge of this language you want to use. Because this post is not about language syntax.

    您要使用的该语言的基础知识。 因为这篇文章与语言语法无关。
  • VS Code editor.

    VS代码编辑器。
  • Compiler/interpreter for this language.

    此语言的编译器/解释器。
  • Code Runner extension for VS Code.

    VS Code的Code Runner扩展。
  • Internet connection. (Just for installation)

    网络连接。 (仅用于安装)

VS Code和编译器/解释器的安装 (VS Code and Compiler/interpreter installation)

At first install VS Code and compiler/interpreter. You can take help from Google. Make sure that path of the compiler/interpreter has been set to the system. Open your terminal and check the version of this compiler/interpreter. If you are able to see the version then path setup is done successfully.

首先安装VS Code和编译器/解释器。 您可以从Google获得帮助。 确保已将编译器/解释器的路径设置为系统。 打开终端,然后检查此编译器/解释器的版本。 如果您能够看到版本,则路径设置成功完成。

代码运行器安装 (Code Runner Installation)

Code Runner is a VS Code extension which allows running code snippet or file written in various language.

Code Runner是VS Code扩展,它允许运行以各种语言编写的代码段或文件。

C, C++, Java, JavaScript, PHP, Python, Perl, Perl 6, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, F# (.NET Core), C# Script, C# (.NET Core), VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml Script, R, AppleScript, Elixir, Visual Basic .NET, Clojure, Haxe, Objective-C, Rust, Racket, AutoHotkey, AutoIt, Kotlin, Dart, Free Pascal, Haskell, Nim, D, Lisp, Kit, and custom command.

C,C ++,Java,JavaScript,PHP,Python,Perl,Perl 6,Ruby,Go,Lua,Groovy,PowerShell,BAT / CMD,BASH / SH,F#脚本,F#(.NET Core),C#脚本,C#( .NET Core),VBScript,TypeScript,CoffeeScript,Scala,Swift,Julia,Crystal,OCaml脚本,R,AppleScript,Elixir,Visual Basic .NET,Clojure,Haxe,Objective-C,Rust,Racket,AutoHotkey,AutoIt,Kotlin ,Dart,Free Pascal,Haskell,Nim,D,Lisp,Kit和自定义命令。

You can download Code Runner from this link or by searching in VS Code extension tab.

您可以从此链接或通过在VS Code扩展选项卡中搜索来下载Code Runner。

Image for post
Code Runner in Extensions tab
扩展选项卡中的代码运行器

After installation, restart VS Code.

安装后,重新启动VS Code。

现在测试此设置 (Now Test This Setup)

Open or create a file in VS Code and write some code for testing. Example, for C++,

在VS Code中打开或创建文件,并编写一些代码进行测试。 例如,对于C ++,

#includes<iostream>
using namespace std;int main()
{
cout << "I am running inside VS Code";
}

There are four way to run a code:

有四种运行代码的方式:

  • Right-click in mouse and select Run Code.

    右键单击鼠标,然后选择“运行代码”。
  • Use shortcut Ctrl+Alt+N.

    使用快捷键Ctrl + Alt + N。
  • Press F1 and select Run Code.

    按F1键,然后选择“运行代码”。
  • Press triangle (run button) from the toolbar.

    从工具栏按三角形(运行按钮)。

After running a code you see the output in the output tab. But there is a problem. The output tab is by default read-only. You cannot give input in it. So a program with user input can not run successfully in the output tab.

运行代码后,您会在输出选项卡中看到输出。 但有一个问题。 默认情况下,输出选项卡是只读的。 您不能在其中输入任何内容。 因此,带有用户输入的程序无法在输出选项卡中成功运行。

#include<bits/stdc++.h>
using namespace std;int main()
{
string name;
cout << "Enter your name : ";
cin >> name;
cout << "Hello, Mr. " << name;
}
Image for post
Output tab in VS Code
VS Code中的“输出”选项卡

But we can solve this problem if we can run the program in the terminal tab. Oh, there is a tip! If you want to stop a program before terminate then use shortcut Ctrl+Alt+M.

但是,如果我们可以在终端选项卡中运行该程序,则可以解决此问题。 哦,有个小费! 如果要在终止之前停止程序,请使用快捷键Ctrl + Alt + M。

在“终端”选项卡中运行程序 (Run Program in Terminal Tab)

For this go to File > Preference > Setting > Extension. Then click to Run Code Configuration. After scrolling, you found a checkbox named Run in Terminal. Check this box.

为此,转到File > Preference > Setting > Extension 。 然后单击Run Code Configuration 。 滚动后,您发现了一个名为Run in Terminal的复选框。 选中此框。

Or you can do it by going to setting.json file and adding this code :

或者,您可以通过转到setting.json文件并添加以下代码来做到这一点:

"code-runner.runInTerminal": true

From now program run in the terminal tab. And you able to run the program in VS Code directly.

从现在开始,程序在“终端”选项卡中运行。 而且您可以直接在VS Code中运行该程序。

To read this article in Bangla visit this link:ডিরেক্টলি কোড রান করার জন্য VS Code সেটআপ

要阅读孟加拉语中的这篇文章,请访问以下链接: VS Codeসেটআপ

翻译自: https://medium.com/@suvashkumar.naogaon/vs-code-setup-for-running-program-directly-9ed418419e11

pycharm代码运行程序

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值