簡體   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

首先,我要說我對python和編程完全是一個新手,但我確實很想學習,因此,如果您可以嘗試使用術語,那么初學者就會明白這對我有很大幫助。 確定在對如何在kali Linux中使用python進行了令人沮喪的搜索之后,我也無法在該文件中運行文件,我在Windows 10 OS上下載了該文件,然后制作了一個基本腳本,如下所示:

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

非常簡單的權利。 將其保存為math.py並進入了cmd提示符(因為wikki告訴我了),然后鍵入math py的位置:

 cd C:\Users\Mitchel\Documents

我在這里閱讀了一個問題,該問題告訴我使用cd輸入位置。 python回應:

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

SyntaxError:語法無效

所以我決定繼續嘗試進行下一步,然后輸入

python math.py

並得到相同的錯誤。 我嘗試雙擊該文件,然后嘗試“打開方式”並單擊python。 我想知道我可以在notepad或notepad ++中鍵入代碼並在開始之前對其進行測試,因為它實際上很難在命令提示符本身中編寫代碼。

這些是要在系統命令提示符下輸入的命令,但是您正在Python解釋器中輸入它們。 大多數教程假定您知道如何解決系統終端問題。 請參見下面的演示。

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