1. Install python
The first step, the Python installation under windows is generally installed through the software installation package rather than the command line, so we must first download the latest Python installation package on the official Python homepage.
The download address is: https://www.python.org/downloads/
We need to manually add environment variables: Right-click My Computer -> Properties -> Click Advanced System Settings -> Click Environment Variables -> Click PATH -> At the end Add our Python installation path -> click OK. It is represented by a picture:
The way to add environment variables, we add at the end of PATH:
C:\Users\APP_Server\AppData\Local\Programs\Python\Python36\;
The problem to pay attention to in this process is that when adding the PATH path, you need to add a semicolon at the end. Now we enter "Python" in the browser again, and we can enter and exit commands directly in the console:
2. Install pip
Download address: https://pypi.python.org/pypi/pip#downloads
After downloading, extract pip-9.0.1.tar to the executable directory:
Execute the following command:
python setup.py install
After the execution is complete, execute the following command in the command line window:
pip list
We will find that this command is not recognized either. Through the previous step, we can know that it is because the environment variable is not added.
According to the method of adding environment variables introduced earlier, we add at the end of PATH:
C:\Users\APP_Server\AppData\Local\Programs\Python\Python36\Scripts\;
Finally, execute pip list again and find that it is successful;
3. pip tool upgrade
If you are executing the pip
command , the following output is required:
You are using pip version 7.1.2, however version 8.1.2 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
It prompts you: Your current pip
tool version is not up to date and needs to be updated. You can completely ignore it, but I am a more sophisticated person, so the command to update the pip
tool is as follows, execute the following command:
python -m pip install --upgrade pip
Now, no more: prompts you to update the output of the pip tool .
4. Install third-party libraries
1. Use the pip
command line tool to download the third-party library you need online
Q: What is it
pip
?
A:pip
It is Python 's package management system, a command-line tool that comes with the Python language, which can install and manage third-party software packages.
The command to install a package using the pip tool is:
pip install some-package-name
Example: Install requests third-party library
We now download a third-party library named: requests . (This library is a Python third-party library for handling HTTP .) Execute the following command in the command line window:
pip install requests
In this way, the requests third-party library is downloaded and installed.
Add: to your script to import requests
use the Requests library.
Q: If you execute the
pip install some-package-name
command, it outputs: No such package found. For example, execute:pip install opencv
command, it will output:
Could not find a version that satisfies the requirement opencv (from versions: ) No matching distribution found for opencv
If you encounter such a situation and then solve it?
A: In this case, it is most likely the reason for hitting the wall. At this time, we need to manually download the installation package of the relevant third-party library.
2. Manually download the third-party library, and then use the pip
command to install
When using pip to install, sometimes encounter the phenomenon of slow Internet or hit the wall, then we go to this website to manually download the installation package you need: http://www.lfd.uci.edu/~gohlke/pythonlibs/ . The Python third-party libraries in this website can be said to be all-encompassing.
Example: Install the matplotlib third-party library
Step 1. Go to this website: http://www.lfd.uci.edu/~gohlke/pythonlibs/
Step 2. Press the key combination: Ctrl + F to find the keyword: matplotlib , click on the matplotlib below
Now you can see the matplotlib version below, because I am using Python 3.6.0 and my computer is 64 bit, so I choose to download: matplotlib-2.2.2-cp36-cp36m-win_amd64.whl
Step 3. Download it, and note the download path:
我的是在
D:\Downloads\
matplotlib-2.2.2-cp36-cp36m-win_amd64.whl
Step 4. After the download is complete, in the command prompt window , execute the following command (where the package must enter the absolute path):
pip install
D:\Downloads\
matplotlib-2.2.2-cp36-cp36m-win_amd64.whl
After successful installation, the following information is output:
Processing d:\downloads
\
matplotlib-2.2.2-cp36-cp36m-win_amd64.whl
Installing collected packages: matplotlib-python Successfully installed
matplotlib
-python-2.2.2
5. Two commonly used functions of matplotlib
1. 2D drawing
1) Description:
Draw the intersection of r=1 and r=2cosθ in the polar coordinate system
(when I didn’t draw it, I really didn’t see that r=2cosθ was also a perfect circle)
2) Program
- import numpy as np
- import matplotlib.pyplot as plt
- plt.figure(1)
- ax = plt.subplot(111)
- x = np.linspace( 0, np.pi * 2, 200) # Between 0 and 2pi, evenly generate an array of 200 points
- # r = 2cosθ
- r = 2 * np.cos(x) # radius
- ax.plot(r * np.cos(x), r * np.sin(x))
- # r = 1
- r = 1
- ax.plot(r * np.cos(x), r * np.sin(x))
- plt.show()
3) Running result
2. 3D drawing
1) Description:
Draw a graph of the vector function r(t)=(sint, cost, t), that is, the coordinates x, y, and z of the vector r are all functions of t, respectively x(t)=sint, y(t )=cost, z(t)=t. The function can be regarded as the flight curve of the "hornet", that is, at time t, its position in space is (x, y, z), and its derivative (flight speed) x'(t)=cost, y' (t)=-sint,z=1, that is, r'(t)=(cost,-sint,1)
2) Program
- import numpy as np
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- fig = plt.figure(1)
- ax = fig.add_subplot( 1, 1, 1, projection= '3d') # Specify three-dimensional space for drawing
- t = np.linspace( 0, 4, 200) # Between 0 and 4, evenly generate an array of 200 points
- theta = t * 2 * np.pi # angle
- # r(t)=(sint,cost,t)
- z = t
- x = np.sin (theta)
- y = np.cos(theta)
- ax.plot(x, y, z, label='r(t)')
- # r’(t)
- z = 1
- x = np.cos(theta)
- y = -np.sin(theta)
- ax.plot(x, y, z, label='r\'(t)')
- ax.legend() jpg521.com
- plt.show()