When we do Python experiments or write code, we always need to import various libraries and packages or create an environment. These libraries and packages need us to learn to download and call. The following is a simple example of python installation library pygame library, Anaconda creates the environment and installs the package needed for the experiment as an example, and the other various download and installation steps are the same. help.
python installation library pygame library
pygame: pygame is a python third-party cross-platform library designed for the development of 2D games. Developers use pygame to define interfaces, which can conveniently and quickly realize GUI creation, graphics and image drawing, user keyboard and mouse operation etc.
Implements pygame in common python software installations. Take pycharm and Anaconda as examples.
1. Install directly inside pycharm
Open the file of pycharm and click Settings.
Open python interpreter, you can see the version of the interpreter, to download pygame, you need to click “ + “.
Input: pygame, you can see the version number of pygame, click to install.
Installation successful interface.
Input: import pygame
, import pygame and run it to try the effect.
You can see that there is no error, which proves that we can directly Called pygame. The installation steps of other libraries in pycharm are the same as pygame.
2. Install pygame in Anaconda
Open all applications on your computer.
Open Anaconda Prompt under Anaconda.
Then enter: python -m pip install --upgrade pip
,
To view the version of pip, enter: pip -V
View Anaconda list: Enter: conda list
View python: where python
You can see that my computer has three pythons. This is because there are some residues that have not been deleted when python was just installed before, but it does not affect it, because my Anaconda has its own python environment, and one is the python explanation I made for pycharm. device.
Then enter pip install pygame
You can see that the installation is successful.
But it can’t be used when I open it. If the python environment you started is not as complicated as mine, then you can import it directly. If you can’t import it successfully, then I will teach you how to install pygame Import into the environment that needs to be tested.
3. Anaconda correctly installs the pygame module into the tensorflow environment
View Anaconda environment: conda env list
You can see that there are three environments in my Anaconda, install pygame in tensorflow.
Enter: pip install pygame
You can see that pygame has been installed on my computer, but it is installed in the basic environment. It needs to be installed in the environment I created, so enter the environment first and then install it.
First delete pygame, open the D drive, and enter: pygame.
Delete pygame and pygame-2.4.0.dist.info.
Enter: conda activate tensorflow
to enter the tensorflow environment.
Enter: pip install pygame
Then add it to tensorflow and run: import pygame
, you can see that it is successful, which proves that it can be used.
4. Install various environments and various python libraries on Anaconda software
Open Anaconda
1) Create Anaconda environment: Take creating turtle as an example.
Enter the library name:
Finally click: Create, just wait for the creation.
Remove environment method:
You can also use commands to remove, take pygame as an example.
Open Anaconda Prompt
Step 1: Exit the environment first
conda deactivate
Step Two: Delete the Environment
conda remove -n environment name to be deleted --all
Enter: y
Finally, it was successfully deleted. Go back to Anaconda to check, and found that there is no pygame environment anymore.
2) Add various python packages to the environment
Take downloading and installing the xlrd package in anaconda as an example.
Steps: anaconda->Environments –>tensorflow->Not installed, input: xlrd, check the pop-up option, and then click Apply. Just turn it on again.
Finally, a commonly used anaconda command diagram is attached: