pyinstaller package alien invasion
Because the title can be understood by novices, so in this section we will briefly write about the preparatory work, and then directly package the alien invasion so that it can run on the computers of friends, so, next ,let's start!
1. pip installation
First of all: pip must be available, because it is very simple to install a third-party library in pip, and often a single command can be installed successfully, which can save a lot of effort. I have seen many ways to install pip, which one is the most convenient? Hey, I checked pip when I downloaded the python compiler, so I don't know, what do you think? (smirk) Huh? have no idea? Um, well, the picture above! That's it, that's it!
I installed it with just a touch of my finger, haha, now the newer python version comes with pip, so when you download it, just check it by the way.
What if pip was not checked when installing the compiler before? There are too many methods, but I haven’t tried them. I checked and found that they are very simple. I won’t talk about them here. There are too many installation methods on Baidu, CSDN, etc.
With pip, the next step is to install the pyinstaller library.
Two: Installation of pyinstaller library
The steps are very simple, I will not upload the picture, press and hold win+R, enter CMD to run, and then, do you feel that the black frame suddenly feels internal, yes, that’s right, it’s pretty cool. Then enter pip install pyinstaller and press Enter, and wait until the installation is complete. After finishing the work, it's time to get ready to get down to business, music, let's go! ! !
Three: Alien Invasion Packing
When pyinstaller packs files, sometimes it encounters many problems. Sometimes a simple package file cannot run the program successfully. When there are multiple code files, it is impossible to pack only one, because many things are between modules. They are related to each other, so, here is the simplest way to do it in one step without complicated steps. After win+R input CMD to run, input: pyinstaller alien_invasion.py -p scoreboard.py -p alien.py -p bullet.py -p button.py -p game_functions.py -p game_stats.py -p settings.py -p ship.py Yes, it is very simple, after pyinstaller is a py file followed by -p, it is as simple as that, every code file must be filled in, and there must be one. Oh yes, there is one point that needs to be paid attention to, the path in CMD must be in the same directory as the py file invaded by aliens, otherwise these files will not be found, that’s it.
I put all these under the F drive, so I have to correspond to the positions. As shown below.
Next type and run: pyinstaller alien_invasion.py -p scoreboard.py -p alien.py -p bullet.py -p button.py -p game_functions.py -p game_stats.py -p settings.py -p ship.py Just started packing.
It took less than a minute, and the package was quickly completed. After that, you can find that the generated dist folder contains an alien_invasion folder, just open it and you will be there.
After opening it, you will exclaim, what? ? ? What the hell is this, hey, the same sentence, look at my name, then go to alien_invasion.exe, open it! ! !
Then, you are not calm anymore, you are a little impatient, a little helpless, and then you want to scold me a little bit, what a goddamn horse, why don't you still flash back! It's useless to waste so long listening to your blind instructions here.
NO! NO! NO! Handsome people will always have a little bit of a problem, don't panic, small scenes, there is still one step to go! Do you believe it or not?
Look below, is there a similar thing in the alien.py and ship.py codes of the alien invasion in the previous section?
self.image = pygame.image.load('images/alien.bmp')
self.image = pygame.image.load('images/ship.bmp')
That’s right, it’s the pictures of aliens and spaceships. Think about it, I gave you pictures~ Sorry, I forgot when I introduced it in the last section...I put the picture folder at the end, and I’ll get it later It's alright... (embarrassed)
Once you have the folder for the pictures, put the folder in the alien_invasion folder and that's it.
Try again and see if it’s okay, haha I didn’t lie to you ( ^▽ ^ )
Okay, you’re done here, let’s send it to your friends to experience, oh, yes, don’t just Send that alien_invasion.exe, you have to send all the folders, just go here, I put the folders of aliens and spaceships below, remember to download~
Link: https://pan.baidu.com/s/1ikc6P7VF7eYq6XoRH0mqgQ
Extraction code: 1234
emm... In the future, CSDN will be used as a record of my learning and growth. I am new here, and I hope to get everyone's support. There will inevitably be various small problems in the content. I also hope that everyone can correct my mistakes. , urging me to keep learning and improving. I am only a freshman. The next few years will be very long, but I feel that it will be fleeting. So, in these short few years, I will work hard to do what I want to do. Going back to this page, I hope that at that time, I would not think about the decadent past and not be afraid of a bright future! come on!