python3 --version显示“NameError:name'python3'is not defined” [英] python3 --version shows "NameError: name 'python3' is not defined"

查看:8372
本文介绍了python3 --version显示“NameError:name'python3'is not defined”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们键入

  python3 --version(或--V)



它应该向我们展示python的版本吧?



我这样做我得到以下错误:


NameError:name'python3'未定义


< blockquote>

这也是我尝试使用

安装pip的情况。

  python3 get-pip.py 


解决方案

python3 是不是Python语法,它是 Python二进制本身,你运行到交互式解释器。



您会在命令行与Python提示混淆。打开控制台(Windows)或终端(Linux,Mac),使用 dir ls 从命令行浏览您的文件系统。



如果您正在输入>>> 提示,表示您的地址不正确, Python解释器本身,它只需要Python语法。如果从命令行启动Python提示符,请在此处退出并返回到命令行。如果您从IDLE或IDE中启动解释器,那么您需要作为单独的程序打开终端或控制台。



其他程序,人们经常混淆Python语法;这些实际上是在命令提示符下运行的程序:




  • python python2.7 python3.5 等。

  • pip pip3

  • virtualenv

  • ipython

  • easy_install

  • setup.py - 这是一个脚本,需要运行 python setup.py [...] 。



如果给出参数, > SyntaxError 异常,但基本原因是相同的:

 > pip install foobar 
文件< stdin>,第1行
pip install foobar
^
语法错误:语法无效
pre>

When we type

python3 --version (or --V)

it is supposed to show us the version of the python right?

However, when I do this I get the following error:

NameError: name 'python3' is not defined

This is also the case when I tried to install the pip by using

python3 get-pip.py

解决方案

python3 is not Python syntax, it is the Python binary itself, the thing you run to get to the interactive interpreter.

You are confusing the command line with the Python prompt. 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.

If you are typing at a >>> prompt you are in the wrong place, that's the Python interpreter itself and it only takes Python syntax. If you started the Python prompt from a command line, exit at this point and go back to the command line. If you started the interpreter from IDLE or in an IDE, then you need to open a terminal or console as a separate program.

Other programs that people often confuse for Python syntax; each of these is actually a program to run in your command prompt:

  • python, python2.7, python3.5, etc.
  • pip or pip3
  • virtualenv
  • ipython
  • easy_install
  • setup.py -- this is a script you need to run with python setup.py [...].

If given arguments, you'll get a SyntaxError exception instead, but the underlying cause is the same:

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

这篇关于python3 --version显示“NameError:name'python3'is not defined”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆