python3 --version shows “NameError: name 'python3' is not defined”

前端 未结 2 720
小蘑菇
小蘑菇 2020-11-22 13:51

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 t

相关标签:
2条回答
  • 2020-11-22 14:02

    If you're using windows you can try in a Python prompt:

    >>>>import pip
    >>>>pip.main(['install', 'foobar'])
    
    0 讨论(0)
  • 2020-11-22 14:13

    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 >>> or In [number]: 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
    • django-admin
    • conda
    • flask
    • scrapy
    • setup.py -- this is a script you need to run with python setup.py [...].
    • Any of the above together with 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:

    >>> pip install foobar
      File "<stdin>", line 1
        pip install foobar
                  ^
    SyntaxError: invalid syntax
    
    0 讨论(0)
提交回复
热议问题