In order to use matlab commands in python, that is, import numpy as np and import matplotlib.pyplot as plt these two commands can run, you need to enter pip install matplotlib in the cmd command window, or import numpy as np ModuleNotFoundError: No module named 'numpy' error.
To achieve this step, you need to upgrade pip. At this time, you need to enter python -m pip install –upgrade pip in the cmd command window. After the upgrade is complete, enter pip install matplotlib.
Two points to note:
Before entering python -m pip install –upgrade pip, you need to change the path of the cmd window to the path of python, such as my F:\Py, otherwise it will appear,'python' is not an internal or external command, nor is it operable Program or batch file.
Before entering pip install matplotlib, you need to change the path of the cmd window to the path of pip, such as my F:\Py\Scripts, otherwise it will appear,'pip' is not an internal or external command, nor is it an executable program or batch file .
Of course, the above two points need to be changed to the path pointing to python and pip when the environment variables are not changed.
Summary summary
Open the cmd window, change the path F:\Py to point to python, and enter python -m pip install –upgrade pip to upgrade pip
Continue in the cmd window, change the path F:\Py\Scripts to point to pip, and then enter pip install matplotlib to install this package
Then write import numpy as np and import matplotlib.pyplot as plt in the function and it can run properly, for example
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(0,2*np.pi,100)
y=np.sin(2*x)
plt.plot(x,y)
plt.show()
Finally, talk about the basic operations of cmd
Enter the cmd command window: Open and right-click the Microsoft logo in the lower left corner, click Run, and enter cmd to enter.
Common operations C:\users cd.. Return to the previous level C:\
C:\users F: Enter F drive F:\
F:\ cd Py Enter the folder F:\Py under the F drive
The above is the whole content of this article, I hope it will be helpful to everyone's study.
Recommended Posts