小书在学习过程中用到了Matplotlib绘图,然后因为没有安装报错,所以就采用 pip install matplotlib ,安装出错了。
C:\Users\Shu\Desktop>pip install matplotlib
Collecting matplotlib
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/matplotlib/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/matplotlib/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/matplotlib/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/matplotlib/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)': /simple/matplotlib/
Could not find a version that satisfies the requirement matplotlib (from versions: )
No matching distribution found for matplotlib
所以上网查了一下,发现是采用下面这个语句来安装的:
C:\Users\Shu\Desktop>python -m pip install matplotlib
Collecting matplotlib
Downloading https://files.pythonhosted.org/packages/f1/f2/0e89288925f87716499f1984c3d7076f4eef2c93db7e30df4844b6e30978/matplotlib-3.0.1-cp36-cp36m-win_amd64.whl (8.9MB)
100% |████████████████████████████████| 8.9MB 1.0MB/s
Requirement already satisfied: numpy>=1.10.0 in c:\users\shu\appdata\local\programs\python\python36\lib\site-packages (from matplotlib) (1.15.3)
Collecting python-dateutil>=2.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/74/68/d87d9b36af36f44254a8d512cbfc48369103a3b9e474be9bdfe536abfc45/python_dateutil-2.7.5-py2.py3-none-any.whl (225kB)
100% |████████████████████████████████| 235kB 397kB/s
Collecting cycler>=0.10 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/71/e8/6777f6624681c8b9701a8a0a5654f3eb56919a01a78e12bf3c73f5a3c714/pyparsing-2.3.0-py2.py3-none-any.whl (59kB)
100% |████████████████████████████████| 61kB 1.3MB/s
Collecting kiwisolver>=1.0.1 (from matplotlib)
Downloading https://files.pythonhosted.org/packages/44/72/16630c3392eba03788ad87949390516bbc488e8e118047a3b824631d21a6/kiwisolver-1.0.1-cp36-none-win_amd64.whl (57kB)
100% |████████████████████████████████| 61kB 1.2MB/s
Requirement already satisfied: six>=1.5 in c:\users\shu\appdata\local\programs\python\python36\lib\site-packages (from python-dateutil>=2.1->matplotlib) (1.11.0)
Requirement already satisfied: setuptools in c:\users\shu\appdata\local\programs\python\python36\lib\site-packages (from kiwisolver>=1.0.1->matplotlib) (39.1.0)
Installing collected packages: python-dateutil, cycler, pyparsing, kiwisolver, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.0.1 matplotlib-3.0.1 pyparsing-2.3.0 python-dateutil-2.7.5
这个 python - m 起什么作用呢?
C:\Users\Shu\Desktop>python --help
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
-b : issue warnings about str(bytes_instance), str(bytearray_instance)
and comparing bytes/bytearray with str. (-bb: issue errors)
-B : don't write .pyc files on import; also PYTHONDONTWRITEBYTECODE=x
-c cmd : program passed in as string (terminates option list)
-d : debug output from parser; also PYTHONDEBUG=x
-E : ignore PYTHON* environment variables (such as PYTHONPATH)
-h : print this help message and exit (also --help)
-i : inspect interactively after running script; forces a prompt even
if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-I : isolate Python from the user's environment (implies -E and -s)
-m mod : run library module as a script (terminates option list)
-O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
-OO : remove doc-strings in addition to the -O optimizations
-q : don't print version and copyright messages on interactive startup
倒数第四行:意思是将库中的python模块用作脚本去运行。
惭愧!我也没理解是什么个意思。
最后,测试一下:
C:\Users\Shu\Desktop>python
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> exit()
大功告成!!!