2023 size Python installation library takes 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 require us to learn to download and call them. The following is a simple example of python installation library pygame library , Anaconda creation environment and installation of packages required for experiments . Other download and installation steps are the same. I hope it will be helpful to everyone.

python installation library pygame library

pygame : pygame is a python third-party cross-platform library designed for developing 2D games. Developers use pygame to define interfaces and can easily and quickly implement graphical user interface creation, graphics and image drawing, user keyboard and mouse operations, etc.
Implement pygame in common python software installations. Take pycharm and Anaconda as examples.

1. Install directly inside pycharm

Open the pycharm file and click Settings .

Please add image description
Open the python interpreter and you can see the version of the interpreter. To download pygame, you need to click " + ".

Please add image description
Enter: pygame , you can see the version number of pygame, click to install.

Please add image description

Installation success interface.

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

Please add image descriptionYou can see that no error is reported, which proves that we can call pygame directly . The installation steps for other libraries in pycharm are the same as those for pygame.

2. Install pygame in Anaconda

Open all apps on your computer.

Please add image description

Open Anaconda Prompt under Anaconda .

Please add image description

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

Please add image description

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

Please add image description

To view the Anaconda listing: enter:conda list

Please add image description
View python:where python

Please add image description

You can see that my computer has three pythons. This is because there are some remnants that were not deleted when I first installed python, but it does not affect it because my Anaconda has its own python environment, and one of them is the python explanation I made for pycharm. device.

Please add image description

Then enterpip install pygame

Please add image descriptionYou can see that the installation was successful.

But when I open it, it doesn't work. If the python environment you started with is not as complicated as mine, then yours can be imported directly. If it cannot be imported successfully, then I will teach you how to use pygame. Import into the environment where experiments are required.

Please add image description

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

Check out the Anaconda environment:conda env list

Please add image description

You can see that there are three environments in my Anaconda, and pygame is installed in tensorflow .

enter:pip install pygame

Please add image 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 drive d and enter: pygame.

Please add image description
Delete pygame and pygame-2.4.0.dist.info.

Please add image description

Enter: conda activate tensorflow, enter the tensorflow environment.

Please add image description

enter:pip install pygame

Please add image 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 image description

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

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

Please add image description

Finally click: Create and wait for creation.

Remove environment method:

Please add image description

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

Please add image description

Step 1: Exit the environment first

conda deactivate

Step 2: Delete the environment

conda remove -n  需要删除的环境名 --all

Please add image description
Input: y

Please add image description

Finally, it was deleted successfully. I returned to Anaconda to check and found that there was no pygame environment anymore.

Please add image 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, enter: xlrd, check the pop-up option, and then click Apply. Just open it again.

Please add image description

Finally, here is a diagram of commonly used anaconda commands:

Please add image description

Guess you like

Origin blog.csdn.net/qq_62127918/article/details/130801330