python打包問題解決方案

2021-08-25 11:00:21 字數 3471 閱讀 9513

用python寫了乙個 打外星人 遊戲,在python執行正常。

用pyinstaller打包,報  找不到指定的模組

解決方案:

一、geany編碼首選項中預設編碼 由 utf-8 改為  簡體中文(gbk)

二、alien.py

原**:

def __init__(self,ai_settings,screen):

# initial a alien and set it a location

super(alien,self).__init__()

self.screen = screen

self.ai_settings = ai_settings

# load a alien picture and set it's rect 屬性

self.image = pygame.image.load('images/alien.bmp')

self.rect = self.image.get_rect()

改之後def __init__(self,ai_settings,screen):

# initial a alien and set it a location

super(alien,self).__init__()

self.screen = screen

self.ai_settings = ai_settings

if getattr(sys, 'frozen', false):

path = sys._meipass  # this is for when the program is frozen

else:

path = os.path.dirname(__file__)  # this is when the program normally runs

# load a alien picture and set it's rect

self.image = pygame.image.load(os.path.join(path,'images\\alien.bmp'))

self.rect = self.image.get_rect()he program normally runs

三、ship.py

原**:

class ship(sprite):

# store alien invasion 's setting class

def __init__(self,ai_settings,screen,pic_type):

# initcial ship and set it init location

super(ship,self).__init__()

self.screen = screen

self.ai_settings = ai_settings

# load ship image and get it outjoin re********

if pic_type == 'big':

self.image = pygame.image.load('images/ship.bmp')

elif pic_type == 'small' :

self.image = pygame.image.load('images/ship_small.bmp')

self.rect = self.image.get_rect()

self.screen_rect = screen.get_rect()

改之後:        

import sys

class ship(sprite):

# store alien invasion 's setting class

def __init__(self,ai_settings,screen,pic_type):

# initcial ship and set it init location

super(ship,self).__init__()

self.screen = screen

self.ai_settings = ai_settings

if getattr(sys, 'frozen', false):

path = sys._meipass  # this is for when the program is frozen

else:

path = os.path.dirname(__file__)  # this is when the program normally runs

# load ship image and get it outjoin re********

if pic_type == 'big':

self.image = pygame.image.load(os.path.join(path,'images\\ship.bmp'))

elif pic_type == 'small' :

self.image = pygame.image.load(os.path.join(path,'images\\ship_small.bmp'))

self.rect = self.image.get_rect()

self.screen_rect = screen.get_rect()

四、button.py 字符集

原**:

import pygame.font

class button():

def __init__(self,ai_settings,screen,msg):

# initial the buttom's atribute

self.screen = screen

self.screen_rect = screen.get_rect()

self.width,self.height = 200,50

self.button_color = (0,139,69)

self.text_color = (255,255,255)

self.font = pygame.font.sysfont(none,48)

改之後:    

import pygame.py

class button():

def __init__(self,ai_settings,screen,msg):

# initial the buttom's atribute

self.screen = screen

self.screen_rect = screen.get_rect()

self.width,self.height = 200,50

self.button_color = (0,25,0)

self.text_color = (255,255,255)

self.font = pygame.font.sysfont('sans',48)

五、複製images目錄

pyinstaller沒有複製目錄到打包目錄下,需要手工複製

Jar Hell 問題解決方案

最近看到溫紹錦的jvm基礎,裡面看到這個jar hell問題的解決方法,之前遇到過一次,是乙個資源檔案,當時覺得挺麻煩,不知道還有這個方法,很棒,特地整理了下,記錄到這裡來,這個部落格開了好長時間了,一直以來也懶得寫東西,以後會堅持更新些。classloader classloader thread...

top K問題解決方案

1.使用最大最小堆。求最大的數用最小堆,求最小的數用最大堆。2.quick select演算法。使用類似快排的思路,根據pivot劃分陣列。3.使用排序方法,排序後再尋找top k元素。4.使用選擇排序的思想,對前k個元素部分排序。5.將1000 個數分成m組,每組尋找top k個數,得到m k個數...

Ajax post亂碼問題解決方案

今天測試乙個ajax元件的時候遇到亂碼問題,在網上找了很多解決方案都未能解決,原因可能我出現亂碼的問題不在傳輸過程,而且是在頁面上就已經出現亂碼了,現象很奇怪,我直接把引數賦值為中文後alert,發現是亂碼,所以不管我怎麼設定和在後台解碼都依然是亂碼。後來找到原因,共分兩點 第一 我的meta標籤設...