0

I open cmd.exe in the installed directory and type 'python':

C:\Python34>python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Basic math works fine:

>>> 4+4
8

I can import, but can't seem to do basic things like check the version, or use pip, etc.:

>>> import os
>>> os.getcwd()
'C:\\Python34'


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


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

I'm relatively new to this so might be doing something stupid, but I can't figure out what's going on.

heds1
  • 3,203
  • 2
  • 17
  • 32
  • 2
    try pip install in the commandline, not inside python. – pylang Feb 13 '18 at 07:12
  • 1
    Using pip to install packages is not meant to be used *within* the Python interpreter. You use it from your terminal - e.g. `pip install flask`. The same goes with trying to determine the version. Use the `-V` flag - e.g. `python -V` and `pip -V` – jrd1 Feb 13 '18 at 07:12
  • You confuse the Windows shell command line and the Python command lines. – DYZ Feb 13 '18 at 07:13
  • If you are new to Python I would recommend installing the lastest stable version if possible (Python 3.6 at the moment). I also recommend installing Python using [Anaconda](https://www.anaconda.com/download/). – pylang Feb 13 '18 at 07:30

2 Answers2

2

Notice the triple chevrons (">>>") means you are inside the Python REPL. Install packages either:

  1. outside Python at the commandline (recommended)
  2. inside Python (less common)

Try the first option:

In cmd

> pip install requests
> python                                               # activates python

In Python

>>> import requests
>>> r = requests.get("https://www.google.com")
>>> r.status_code
200
pylang
  • 40,867
  • 14
  • 129
  • 121
1

You cannot do pip install inside the python interpreter. Befor enterig the interpreter, try pip install, if you do not have pip, google for getpip.py.