简体   繁体   English

如何在尝试运行 python 脚本时修复 powershell 终端中未定义的“名称错误'_'

[英]How to fix "name error '_' not defined in powershell terminal while trying to run a python script

I'm trying to make a bot for discord and am running into problems getting it to run.我正在尝试为 discord 制作一个机器人,但在让它运行时遇到了问题。 I have no experience in coding.我没有编码经验。
I copied the scripts into visual studio for a test to see if I can get it to work, and I think I copied it right.我将脚本复制到 Visual Studio 中进行测试,看看我是否可以让它工作,我认为我复制它是正确的。 I just don't know what I'm doing wrong when trying to run it in the terminal.我只是不知道在终端中运行它时我做错了什么。

我的视觉工作室的照片

You have to type python Donnie.py in the terminal and hit enter.您必须在终端中输入python Donnie.py并回车。

Welcome to programming:)欢迎编程:)

The vscode terminal uses the power shell built into Windows. vscode终端使用Windows内置的电源shell。

If you type python in the terminal and press enter, the python executable will be executed and the python interactive window will open.如果您在终端中键入python并按回车键,将执行 python 可执行文件,并打开 python 交互式 Z05B8C74CBD96FBF2DE4C1A352702FB。

Here, you can directly type python language and run, such as print("hello") .在这里,您可以直接输入 python 语言并运行,例如print("hello")

在此处输入图像描述

If what you want to run is a python script file.如果您要运行的是 python 脚本文件。 Then you should use the play button at the top right of the interface and select Run Python File .然后你应该使用界面右上角的播放按钮和 select运行 Python 文件

在此处输入图像描述

If you want to run with the command, use python youfilename.py command in the terminal to run the entire script file.如果要使用命令运行,请在终端中使用python youfilename.py命令运行整个脚本文件。

在此处输入图像描述

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

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