简体   繁体   English

我无法在Windows 10上的cmd或Kali Linux的终端中运行.py文件

[英]I cannot run a .py file in cmd on windows 10, or in the terminal in kali linux

Lets just start by saying I am a complete greenhorn to python and programming altogether but I really do want to learn so if you could try and use terms a beginner would understand that would help me a lot. 首先,我要说我对python和编程完全是一个新手,但我确实很想学习,因此,如果您可以尝试使用术语,那么初学者就会明白这对我有很大帮助。 OK After getting incredibly frustrated googling how to use python in kali Linux couldn't run a file there either, I downloaded it on My Windows 10 OS then I made a basic script that looks like 确定在对如何在kali Linux中使用python进行了令人沮丧的搜索之后,我也无法在该文件中运行文件,我在Windows 10 OS上下载了该文件,然后制作了一个基本脚本,如下所示:

#! /usr/bin/python
a = 122
b = 344
print a + b

very simple right. 非常简单的权利。 saved it as math.py and went the the cmd prompt (because wikki how told me to) then typed in the location of math py : 将其保存为math.py并进入了cmd提示符(因为wikki告诉我了),然后键入math py的位置:

 cd C:\Users\Mitchel\Documents

I read a question on here that told me to use cd to enter the location. 我在这里阅读了一个问题,该问题告诉我使用cd输入位置。 python responded with : python回应:

File "<stdin>", line 1
cd C:\Users\Mitchel\Documents
   ^

SyntaxError: invalid syntax SyntaxError:语法无效

so I decided to go to try going to the next step anyways and just typed 所以我决定继续尝试进行下一步,然后输入

python math.py

and got the same error. 并得到相同的错误。 I tried double clicking the file, I tried "open with" and clicking python. 我尝试双击该文件,然后尝试“打开方式”并单击python。 I want to know I can type code in notepad or notepad++ and test it before I start because its reall hard to actually write the code in the command prompt itself. 我想知道我可以在notepad或notepad ++中键入代码并在开始之前对其进行测试,因为它实际上很难在命令提示符本身中编写代码。

Those are commands to enter at your system's command prompt, but you are entering them in the Python interpreter. 这些是要在系统命令提示符下输入的命令,但是您正在Python解释器中输入它们。 Most tutorials assume that you know how to get around your system's terminal. 大多数教程假定您知道如何解决系统终端问题。 See below for a demonstration. 请参见下面的演示。

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\TigerhawkT3>cd
C:\Users\TigerhawkT3

C:\Users\TigerhawkT3>cd ..

C:\Users>py -c "print(1+2)"
3

C:\Users>py
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> cd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'cd' is not defined
>>> cd ..
  File "<stdin>", line 1
    cd ..
        ^
SyntaxError: invalid syntax
>>> py -c "print(1+2)"
  File "<stdin>", line 1
    py -c "print(1+2)"
                     ^
SyntaxError: invalid syntax
>>> print(1+2)
3
>>>

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

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