Pages

Se afișează postările cu eticheta python 3.4. Afișați toate postările
Se afișează postările cu eticheta python 3.4. Afișați toate postările

joi, 25 mai 2017

PyGame : Fix error install pygame module on python 3.4.

Today I started to install pygame with python 3.4.1.
I got a lot of errors first with pip tool, see all errors.
C:\Python34\Scripts>pip install pygame
Downloading/unpacking pygame
  Running setup.py (path:C:\Users\mythcat\AppData\Local\Temp\pip_build_mythcat\
pygame\setup.py) egg_info for package pygame


    WARNING, No "Setup" File Exists, Running "config.py"
    Using WINDOWS configuration...

    Path for SDL not found.
    Too bad that is a requirement! Hand-fix the "Setup"
    Path for FONT not found.
    Path for IMAGE not found.
    Path for MIXER not found.
    Path for PNG not found.
    Path for JPEG not found.
    Path for PORTMIDI not found.
    Path for COPYLIB_tiff not found.
    Path for COPYLIB_z not found.
    Path for COPYLIB_vorbis not found.
    Path for COPYLIB_ogg not found.

    If you get compiler errors during install, doublecheck
    the compiler flags in the "Setup" file.


    Continuing With "setup.py"
    Error with the "Setup" file,
    perhaps make a clean copy from "Setup.in".
    Traceback (most recent call last):
      File "", line 17, in 
      File "C:\Users\mythcat\AppData\Local\Temp\pip_build_mythcat\pygame\setup.py", line 165, in 
        extensions = read_setup_file('Setup')
      File "C:\Python34\lib\distutils\extension.py", line 164, in read_setup_file
        line = expand_makefile_vars(line, vars)
      File "C:\Python34\lib\distutils\sysconfig.py", line 423, in expand_makefile_vars
        s = s[0:beg] + vars.get(m.group(1)) + s[end:]
    TypeError: Can't convert 'NoneType' object to str implicitly
    Complete output from command python setup.py egg_info:

WARNING, No "Setup" File Exists, Running "config.py"

Using WINDOWS configuration...

Path for SDL not found.

Too bad that is a requirement! Hand-fix the "Setup"

Path for FONT not found.

Path for IMAGE not found.

Path for MIXER not found.

Path for PNG not found.

Path for JPEG not found.

Path for PORTMIDI not found.

Path for COPYLIB_tiff not found.

Path for COPYLIB_z not found.

Path for COPYLIB_vorbis not found.

Path for COPYLIB_ogg not found.

If you get compiler errors during install, doublecheck

the compiler flags in the "Setup" file.

Continuing With "setup.py"

Error with the "Setup" file,

perhaps make a clean copy from "Setup.in".

Traceback (most recent call last):

  File "", line 17, in 

  File "C:\Users\mythcat\AppData\Local\Temp\pip_build_mythcat\pygame\setup.py", line 165, in 

    extensions = read_setup_file('Setup')

  File "C:\Python34\lib\distutils\extension.py", line 164, in read_setup_file

    line = expand_makefile_vars(line, vars)

  File "C:\Python34\lib\distutils\sysconfig.py", line 423, in expand_makefile_vars

    s = s[0:beg] + vars.get(m.group(1)) + s[end:]

TypeError: Can't convert 'NoneType' object to str implicitly

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in C:\Users\mythcat\AppData\Local\Temp\pip_build_mythcat\pygame
Storing debug log for failure in C:\Users\mythcat\pip\pip.log

C:\Python34\Scripts>pip install pygame-1.9.3-cp34-cp34m-win_amd64.whl
pygame-1.9.3-cp34-cp34m-win_amd64.whl is not a supported wheel on this platform.
Storing debug log for failure in C:\Users\mythcat\pip\pip.log

C:\Python34\Scripts>pip3 install pygame-1.9.3-cp34-cp34m-win_amd64.whl
pygame-1.9.3-cp34-cp34m-win_amd64.whl is not a supported wheel on this platform.
Storing debug log for failure in C:\Users\mythcat\pip\pip.log
The solution come with the executable pygame-1.9.2a0-hg_8d9e6a1f2635%2B.win-amd64-py3.4.msi from here and now working very well.

miercuri, 27 ianuarie 2016

PyGame : Effects - part 001.

Today I come one simple and nice tutorial about pygame python module over python version 3.4.
The python script just makes two effects.
First is one fade effect from transparent to black. I also added one green color.
Another effect come with the dizzy star base math python module and random python module.
Because this combined colors green and blue are funny I make star blue.
The script is simple :
  • created variables;
  • make pygame windows; 
  • make fade background function;
  • make one class for shape ( and this can be updated );
  • make loop the game and escape key option;
  •  ... and finally, add shape class and variable into loop pygame script.
Let's see the script:
# Cătălin George Feștilă 
# http://free-tutorials.org

import pygame
import random
import math
from pygame.locals import *

#initialize pygame and random seed
pygame.init()
random.seed()

#transparent to black for fade effect
def background_fade():
    rec = pygame.Surface(screensize)
    if frame != 0:
        rec.set_alpha(10)
        rec.fill((0,0,0))
    else:
        rec.set_alpha(255)
        rec.fill(draw_color)
    screen.blit(rec,(0,0))
    del rec

#all mathmatical shapes
class shape():
    xy = [0,0]   #location
    rot = [0.0,0.0] #rotation
    color = '.'   #color/shape value
    dim_size = 1
 #constructor
    def __init__(self,xy,dim_size,color):
        self.xy = xy
        self.dim_size = dim_size
        
        self.rot = [(random.random()*(math.pi)),.002]
        self.color = color
 
 #define shape
    def set_shape(self,color):
        self.color = color
    
 #draw shape    
    def draw(self):
        #rotation
        self.rot[0] += self.rot[1]
        if self.rot[0] > math.pi*2:
            self.rot[0] -= math.pi*2
        #blue/star
        if self.color == 'blue':
            for x in range(5):
                pygame.draw.aaline(screen,(0,0,255),\
                        (((math.cos(self.rot[0]+(x*((math.pi*2)/5)))*self.dim_size)+self.xy[0]),\
                        ((math.sin(self.rot[0]+(x*((math.pi*2)/5)))*self.dim_size)+self.xy[1])),\
                        (((math.cos(self.rot[0]+((x+2)*((math.pi*2)/5)))*self.dim_size)+self.xy[0]),\
                        ((math.sin(self.rot[0]+((x+2)*((math.pi*2)/5)))*self.dim_size)+self.xy[1])),\
                        1)

#start main pygame effect
while 1:
    #create variable for pygame
    screensize = (640,480)
    screen = pygame.display.set_mode(screensize, 0, 32)
    clock = pygame.time.Clock()
    #set frame 
    frame = 0
    draw_color = [0,255,0]
    #reftime = pygame.time.get_ticks()
    text = pygame.font.Font(None,25)
    #start drawing
    while 1:
        clock.tick(30)
        shapetest=shape((320,240),100,'blue')
        shapetest.draw()
        #check if is pressed any key 
        pygame.event.get()
        #if is press escape key
        if pygame.key.get_pressed()[pygame.K_ESCAPE]:
            pygame.quit()
            exit()
        #print clock.get_fps() on windows title
        pygame.display.set_caption(str(clock.get_fps()))   
        pygame.display.update()
        #start fade background
        background_fade()
        #change var frame for background_fade
        frame += 1
        #stop when frame is 100
        if frame == 100:
         break

    frame = 0
    
    pygame.display.update()
    background_fade()

    frame += 1
I make one screenshot to see how it's working.