简体   繁体   English

python3 --version 显示“NameError: name 'python3' 未定义”

[英]python3 --version shows "NameError: name 'python3' is not defined"

When we type当我们打字

python3 --version (or --V)

it is supposed to show us the version of the python right?它应该向我们展示python的版本,对吗?

However, when I do this I get the following error:但是,当我这样做时,我收到以下错误:

NameError: name 'python3' is not defined NameError: 名称 'python3' 未定义

This is also the case when I tried to install the pip by using当我尝试通过使用安装 pip 时也是这种情况

>>> python3 get-pip.py
  File "<stdin>", line 1
    python3 get-pip.py
              ^
SyntaxError: invalid syntax

python3 is not Python syntax , it is the Python binary itself , the thing you run to get to the interactive interpreter. python3不是 Python 语法,它是Python 二进制文件本身,是您运行以获取交互式解释器的东西。

You are confusing the command line with the Python prompt.您将命令行与 Python 提示符混淆了。 Open a console (Windows) or terminal (Linux, Mac), the same place you'd use dir or ls to explore your filesystem from the command line.打开控制台 (Windows) 或终端(Linux、Mac),这与您在命令行中使用dirls浏览文件系统的位置相同。

If you are typing at a >>> or In [number]: prompt you are in the wrong place, that's the Python interpreter itself and it only takes Python syntax.如果您在>>>In [number]:提示符下键入,则说明您在错误的位置,那是 Python 解释器本身,它只采用 Python 语法。 If you started the Python prompt from a command line, exit at this point and go back to the command line.如果您从命令行启动 Python 提示符,请在此时退出并返回命令行。 If you started the interpreter from IDLE or in an IDE, then you need to open a terminal or console as a separate program.如果您从 IDLE 或在 IDE 中启动解释器,那么您需要将终端或控制台作为单独的程序打开。

Other programs that people often confuse for Python syntax;人们经常因 Python 语法而混淆的其他程序; each of these is actually a program to run in your command prompt:这些中的每一个实际上都是一个在命令提示符下运行的程序:

  • python , python2.7 , python3.5 , etc. pythonpython2.7python3.5等。
  • pip or pip3 pippip3
  • virtualenv
  • ipython
  • easy_install
  • django-admin
  • conda
  • flask
  • scrapy
  • setup.py -- this is a script you need to run with python setup.py [...] . setup.py这是你需要用python setup.py [...]运行的脚本。
  • Any of the above together with sudo .以上任何一项与sudo一起使用。

with many more variations possible depending on what tools and libraries you have installed and what you are trying to do.根据您安装的工具和库以及您尝试执行的操作,可能会有更多变化。

If given arguments, you'll get a SyntaxError exception instead, but the underlying cause is the same:如果给定参数,您将得到SyntaxError异常,但根本原因是相同的:

>>> pip install foobar
  File "<stdin>", line 1
    pip install foobar
              ^
SyntaxError: invalid syntax

If you're using windows you can try in a Python prompt:如果您使用的是 Windows,您可以在 Python 提示符下尝试:

>>>>import pip
>>>>pip.main(['install', 'foobar'])

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

相关问题 NameError:未定义名称“ python3” [Jenkins] - NameError: name 'python3' is not defined [Jenkins] PyQT5和Python3“ exit(a.exec_())” NameError:未定义名称“ a” - PyQT5 and Python3 “exit(a.exec_())” NameError: name 'a' is not defined Python3:NameError:未定义名称'raw_input' - Python3: NameError: name 'raw_input' is not defined NameError:使用python3编译时未定义名称“ unicode” - NameError: name 'unicode' is not defined when compile with python3 NameError:名称“ execfile”未定义在Python3上安装fandjango - NameError: name 'execfile' is not defined installing fandjango on Python3 Python3中的名称错误 - NameError in Python3 在python3上使用python调试器会引发NameError:未定义名称“ raw_input” - Using python debugger on python3 throws NameError: name 'raw_input' is not defined “NameError:当我尝试在 Python3 中使用该变量时,未定义名称‘响应’ - "NameError: name 'response' is not defined when i try to use the variable in Python3 未定义ThreadPoolExecutor [python3] - ThreadPoolExecutor is not defined [python3] 当我在 Python3 中运行这段代码时,它给出了这个错误: NameError: name 'x' is not defined。 我该如何纠正? - When I ran this code in Python3 it gives this error: NameError: name 'x' is not defined. How do I correct this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM