python installation and installation of third-party libraries

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 pipcommand , 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 piptool 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 piptool 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 pipcommand 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 requestsuse the Requests library.

Q: If you execute the pip install some-package-namecommand, it outputs: No such package found. For example, execute: pip install opencvcommand, 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 pipcommand 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 installedmatplotlib-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

 

[python]  view plain copy  
 
  1. import numpy as np  
  2. import matplotlib.pyplot as plt  
  3.   
  4. plt.figure(1)  
  5. ax = plt.subplot(111)  
  6. x = np.linspace( 0, np.pi *  2,  200)   # Between 0 and 2pi, evenly generate an array of 200 points  
  7.   
  8. # r = 2cosθ  
  9. r =  2 * np.cos(x)   # radius  
  10. ax.plot(r * np.cos(x), r * np.sin(x))  
  11.   
  12. # r = 1  
  13. r = 1  
  14. ax.plot(r * np.cos(x), r * np.sin(x))  
  15.   
  16. 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

 

[python]  view plain copy  
 
    1. import numpy as np  
    2. import matplotlib.pyplot as plt  
    3. from mpl_toolkits.mplot3d import Axes3D  
    4.   
    5. fig = plt.figure(1)  
    6. ax = fig.add_subplot( 1, 1, 1, projection= '3d')  # Specify three-dimensional space for drawing  
    7.   
    8. t = np.linspace( 0,  4,  200)   # Between 0 and 4, evenly generate an array of 200 points  
    9. theta = t *  2 * np.pi  # angle  
    10.   
    11. # r(t)=(sint,cost,t)  
    12. z = t   
    13. x = np.sin (theta)  
    14. y = np.cos(theta)  
    15. ax.plot(x, y, z, label='r(t)')  
    16.   
    17. # r’(t)  
    18. z =  1   
    19. x = np.cos(theta)  
    20. y = -np.sin(theta)  
    21. ax.plot(x, y, z, label='r\'(t)')  
    22.   
    23. ax.legend()  jpg521.com
    24. plt.show()  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324810621&siteId=291194637