简体   繁体   English

Python在终端中不起作用(Python 3.4.3,Windows 8.1)

[英]Python not working in terminal (Python 3.4.3, Windows 8.1)

I open cmd.exe in the installed directory and type 'python': 我在安装目录中打开cmd.exe并输入“ 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.: 我可以导入,但似乎无法执行基本操作,例如检查版本或使用pip等:

>>> 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. 我对此还比较陌生,因此可能会做一些愚蠢的事情,但是我不知道发生了什么。

Notice the triple chevrons (" >>> ") means you are inside the Python REPL. 请注意,三重人字形(“ >>> ”)表示您位于Python REPL中。 Install packages either: 安装软件包:

  1. outside Python at the commandline (recommended) 在Python外部的命令行(推荐)
  2. inside Python (less common) 在Python内部 (较不常见)

Try the first option: 尝试第一个选项:

In cmd 以cmd为单位

> pip install requests
> python                                               # activates python

In Python 在Python中

>>> import requests
>>> r = requests.get("https://www.google.com")
>>> r.status_code
200

You cannot do pip install inside the python interpreter. 您不能在python解释器中进行pip安装。 Befor enterig the interpreter, try pip install, if you do not have pip, google for getpip.py. 在输入解释器之前,请尝试安装pip,如果没有pip,请使用google获取getpip.py。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM