简体   繁体   English

使用“python --version”命令显示错误消息

[英]Using "python --version" command bringing up error message

I have Python 3.7.1 on my Windows 10 PC.我的 Windows 10 PC 上有 Python 3.7.1。 I want to install Pandas and firstly need to do some checks to see if I have everything required.我想安装 Pandas,首先需要做一些检查,看看我是否拥有所需的一切。 I tried typing the following to double check the Python version:我尝试输入以下内容来仔细检查 Python 版本:

python --version

but it keeps spitting out the error:但它不断吐出错误:

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined

According to the Pandas website, if this error occurs it's because I need to type it into Python Shell.根据 Pandas 网站,如果发生此错误,那是因为我需要将其输入到 Python Shell 中。 But that's what I'm doing... I know I'm probably missing something really obvious, but I'd really appreciate any hints and tips for this very basic problem...但这就是我正在做的......我知道我可能遗漏了一些非常明显的东西,但我真的很感激这个非常基本问题的任何提示和技巧......

Thanks!谢谢!

You shouldn't be entering python --version in a Python shell.您不应该在 Python shell 中输入python --version Enter it in the cmd.exe shell.在 cmd.exe shell 中输入它。

You probably get this Error:您可能会收到此错误:

在此处输入图片说明

The answer from RasikhJ is right, except you have to use brackets in your Python3 version: RasikhJ 的答案是正确的,只是您必须在 Python3 版本中使用方括号:

import sys
print (sys.version)

If you just want to know your Python version, then use the command line:如果您只想知道您的 Python 版本,请使用命令行:

  1. Search for cmd or command line on your Windows在 Windows 上搜索 cmd 或命令行
  2. Change your folder to the "python.exe" file (something like C:/Users/Username/AppData/Local/Programs/Python/Python36-32) with the "cd" command使用“cd”命令将文件夹更改为“python.exe”文件(类似于 C:/Users/Username/AppData/Local/Programs/Python/Python36-32)
  3. Now you can type in "python --version" and you get your Version现在您可以输入“python --version”并获得您的版本

在此处输入图片说明

Use the sys package:使用 sys 包:

import sys
print sys.version

Or use the platform module:或者使用平台模块:

import platform
print platform.python_version()

You should try py --version in cmd .您应该在cmd尝试py --version

C:\Users\XYZ>py --version
Python 3.8.5

Try py --version in cmd.在 cmd 中尝试py --version

C:\Users\XYZ>py --version
Python 3.8.3  

If you want to see python version in python prompt如果你想在 python 提示符下查看 python 版本
import sys导入系统
print(sys.version)打印(系统版本) 你会得到这个结果

The command which you are trying meant for cmd/terminal prompt.您正在尝试的命令用于 cmd/终端提示。 Also your python environment should be set to get below results您的python环境也应该设置为获得以下结果
在此处输入图片说明

I did the same command/entries in Miniforge Prompt(mambaforge) and had No errors or problems what so ever.. If I use Python 3.10 (64-bit) I get nothing but error messages on just about everything.我在 Miniforge Prompt(mambaforge) 中执行了相同的命令/条目并且没有任何错误或问题。 I'm not a dictionary on commands but Miniforge Prompt(mambaforge) has never given me any problems.我不是命令字典,但 Miniforge Prompt(mambaforge) 从来没有给我任何问题。

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

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