2023-sized Python installation library Take pycharm and Anaconda to install pygame as an example

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.

Please add a picture description
Open python interpreter, you can see the version of the interpreter, to download pygame, you need to click “ + “.

Please add a picture description
Input: pygame, you can see the version number of pygame, click to install.

Please add a picture description

Installation successful interface.

Please add a picture description
Input: import pygame, import pygame and run it to try the effect.

Please add a picture descriptionYou 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.

Please add a picture description

Open Anaconda Prompt under Anaconda.

Please add a picture description

Then enter: python -m pip install --upgrade pip,

Please add a picture description

To view the version of pip, enter: pip -V

Please add a picture description

View Anaconda list: Enter: conda list

Please add a picture description
View python: where python

Please add a picture description

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.

Please add a picture description

Then enter pip install pygame

Please add a picture descriptionYou 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.

Please add a picture description

3. Anaconda correctly installs the pygame module into the tensorflow environment

View Anaconda environment: conda env list

Please add a picture description

You can see that there are three environments in my Anaconda, install pygame in tensorflow.

Enter: pip install pygame

Please add a picture description

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.

Please add a picture description
Delete pygame and pygame-2.4.0.dist.info.

Please add a picture description

Enter: conda activate tensorflow to enter the tensorflow environment.

Please add a picture description

Enter: pip install pygame

Please add a picture description

Then add it to tensorflow and run: import pygame, you can see that it is successful, which proves that it can be used.

Please add a picture description

4. Install various environments and various python libraries on Anaconda software

Open Anaconda
1) Create Anaconda environment: Take creating turtle as an example.
Please add a picture description
Enter the library name:

Please add a picture description

Finally click: Create, just wait for the creation.

Remove environment method:

Please add a picture description

You can also use commands to remove, take pygame as an example.
Open Anaconda Prompt

Please add a picture description

Step 1: Exit the environment first

conda deactivate

Step Two: Delete the Environment

conda remove -n environment name to be deleted --all

Please add a picture description
Enter: y

Please add a picture description

Finally, it was successfully deleted. Go back to Anaconda to check, and found that there is no pygame environment anymore.

Please add a picture description

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.

Please add a picture description

Finally, a commonly used anaconda command diagram is attached:

Please add a picture description