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 .
Open the python interpreter and you can see the version of the interpreter. To download pygame, you need to click " + ".
Enter: pygame , you can see the version number of pygame, click to install.
Installation success interface.
Input: import pygame
, import pygame and run it to try the effect.
You 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.
Open Anaconda Prompt under Anaconda .
Then enter: python -m pip install --upgrade pip
,
To view the version of pip, enter:pip -V
To view the Anaconda listing: enter:conda list
View python:where python
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.
Then enterpip install pygame
You 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.
3. Anaconda correctly installs the pygame module into the tensorflow environment
Check out the Anaconda environment:conda env list
You can see that there are three environments in my Anaconda, and pygame is installed 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 drive d and enter: pygame.
Delete pygame and pygame-2.4.0.dist.info.
Enter: conda activate tensorflow
, 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 an Anaconda environment: Take creating turtle as an example.
Enter the library name:
Finally click: Create and wait for creation.
Remove environment method:
You can also use commands to remove it, taking pygame as an example.
Open Anaconda Prompt
Step 1: Exit the environment first
conda deactivate
Step 2: Delete the environment
conda remove -n 需要删除的环境名 --all
Input: y
Finally, it was deleted successfully. I returned to Anaconda to check and found that there was 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, enter: xlrd, check the pop-up option, and then click Apply. Just open it again.
Finally, here is a diagram of commonly used anaconda commands: