[英]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),这与您在命令行中使用
dir
或ls
浏览文件系统的位置相同。
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. python
、 python2.7
、 python3.5
等。pip
or pip3
pip
或pip3
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 [...]
运行的脚本。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.