I need help installing pypng in Python 3.3

Discussion in 'Python' started by Andrew Robinson, Oct 29, 2012.

  1. On 10/29/2012 05:23 AM, icgwh wrote:
    > Hello all,
    >
    > I am very new to python. I am currently porting a little project of mine from java to python and I need to be able to construct and write png images. I naturally turned myself toward pypng to accomplish this.

    I don't know if this will help, but:

    There is a package called image magic; which can convert any image to
    any other type of image.
    If that would not be a burden to install (most OS's have pre-compiled
    working binaries) -- you could easily write a portable bitmap file to
    disk using python (even without a library) -- and then convert it to png.

    I have a little script I wrote in python to create a canvas, and allow
    you to draw on it using very simple line drawing primitives, and then
    save it to PBM. It's simple enough (only draws lines with different
    pens) that you could examine it and write your own script to do the same
    or better.

    If this interests you, I will see if I can post the py script; or email
    it to you.

    --Andrew.
     
    Andrew Robinson, Oct 29, 2012
    #1
    1. Advertising

  2. Andrew Robinson

    Guest

    Hello all,

    I am very new to python. I am currently porting a little project of mine from java to python and I need to be able to construct and write png images. I naturally turned myself toward pypng to accomplish this.

    I learned from the net that pypng 0.0.13 is supposed to work in Python 3.x when run through '2to3'. However, in my case, it apparently does not.

    I ran into various problems when trying to install it, some of them I couldfix myself. First I attempted to install pip but I couldn't get Windows torecognize pip as an internal command as the prompt informs me.
    Then I tried to directly run "setup.py install" from the pypng folder. It didn't work as I got a syntax error. I noticed that in the beginning of the installation process, the following warning was displayed: "conf[use_2to3 = true] unrecognized configuration option"

    At that point I was already pretty pissed but I managed to make the warningdisappear by updating (installing?) distribute. After that there are no more errors during the installation process and everything seems to work fine.. (This seems still strange to me as 2to3 was present in Tools/Script out of the box)


    I use pydev in Eclipse and pydev reports several error in png.py anytime I want to import or use it. When trying to import from IDLE I get:

    except ValueError, e:
    ^
    Syntax error, line 1863

    that paricular error I was able to fix by changing it to "except ValueErroras e:" but I don't understand why 2to3 didn't do it automatically.
    There are several more errors reported by pydev, here are a few:

    line 1368 : "raise ValueError('Chunk %s too short for checksum.', tag)"
    Undefined variable: tag

    line 2736 : "rows = [map(numpy.uint16, range(0,0x10000,0x5555))]"
    Undefined variable from import: uint16


    The second one made me suspect I needed to install numpy too. As there are no installers for numpy aimed toward Python3.3.

    I decided to install Python2.7 and retry the whole process. Unfortunately Ididn't get much more success. I get the exact same errors in pydev when using the 2.7 version of the interpreter and I cannot install numpy either because when I run the .exe file aimed toward Python 2.7 i get the error message:

    "Python version 2.7 required, which was not found in the registry"

    I then have the option to manually enter the path to Python 2.7 but the textform is greyed out and I can't type in anything.


    At that point I decided to go look for help and Here I am...

    I am truly grateful to anyone who takes the time to help me in this matter.
    Thank you!
     
    , Oct 29, 2012
    #2
    1. Advertising

  3. Andrew Robinson

    Guest

    I probably should have mentioned that I'm under W7 ultimate x64, I'm using eclipse Juno (latest) and pydev 2.7.1
     
    , Oct 29, 2012
    #3
  4. Andrew Robinson

    Guest

    That's very kind of you but I don't think it would be particularly fitted to my needs. The program I'm trying to code creates an image as an 2D array of "pixels" which is defined by RGBA value. My program needs to access and modifies every component of every pixels in the image following a set of rules, kind of like the game of life, only more complex.

    In fact I only need a library to "push" this array of pixels in a displayable format for the GUI and in PNG format to write the image to disk. I don'tneed to do any fancy stuff with the image, just being able to display and write it.
     
    , Oct 29, 2012
    #4
  5. Andrew Robinson

    Guest

    That's very kind of you but I don't think it would be particularly fitted to my needs. The program I'm trying to code creates an image as an 2D array of "pixels" which is defined by RGBA value. My program needs to access and modifies every component of every pixels in the image following a set of rules, kind of like the game of life, only more complex.

    In fact I only need a library to "push" this array of pixels in a displayable format for the GUI and in PNG format to write the image to disk. I don'tneed to do any fancy stuff with the image, just being able to display and write it.
     
    , Oct 29, 2012
    #5
  6. On 10/29/2012 06:39 AM, wrote:
    > That's very kind of you but I don't think it would be particularly fitted to my needs. The program I'm trying to code creates an image as an 2D array of "pixels" which is defined by RGBA value. My program needs to access and modifies every component of every pixels in the image following a set of rules, kind of like the game of life, only more complex.
    >
    > In fact I only need a library to "push" this array of pixels in a displayable format for the GUI and in PNG format to write the image to disk. I don't need to do any fancy stuff with the image, just being able to display and write it.
    >
    >

    Then, actually, what I am suggesting was *almost* perfect.
    To do transparency, you need to write the portable any map (PAM) formation.

    Simply print a text header to a file which says:

    P7
    WIDTH 10
    HEIGHT 10
    DEPTH 4
    MAXVAL 255
    TUPLTYPE RGB_ALPHA
    ENDHDR

    And then dump your 2D array to that same file.
    A very quick example in 17 lines of code:

    io = open( "anyname.pam","w")
    x,y = 10,10
    gray=(128,128,128,255) # R,G,B,A value
    picture = [ [ gray ] * x ] * y # Make a blank gray canvas 2D array

    # Do whatever you want to the 2D picture array here!

    io.write( "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE
    RGB_ALPHA\nENDHDR\n" % (x,y) )

    for yi in xrange( y ):
    for xi in xrange( x ):
    pixel = picture[yi][xi]
    io.write( chr(pixel[0]) ) # R value
    io.write( chr(pixel[1]) ) # G value
    io.write( chr(pixel[2]) ) # B value
    io.write( chr(pixel[3]) ) # A value
    io.flush()

    io.close()

    And that's it. You may of course make this more efficient -- I'm just
    showing it this way for clarity.
    Many programs can read PAM directly; but for those that can't you can
    use nettools, or imagemagick, to convert it to PNG.
     
    Andrew Robinson, Oct 29, 2012
    #6
  7. Andrew Robinson

    Guest

    >
    > Do you have the file c:\Python33\Lib\site-packages\pypng-0.0.13-py3.3.egg ?
    >
    > If not, you have not successfully installed pypng. Please try one of
    >
    > the methods I gave above.


    Yes I do have the egg.

    I'm gonna try to summarize:

    I don't have installations problems anymore but it seems that png.py is not run through 2to3 although it should since the setup.py is properly configured:

    if sys.version_info >= (3,):
    conf['use_2to3'] = True

    I even tried to skip the if to ensure the second line is executed but nothing changed.

    I don't know what I'm doing wrong but it seems that png.py is not properly translated to Python 3.
     
    , Oct 29, 2012
    #7
  8. Andrew Robinson

    Guest

    >
    > Do you have the file c:\Python33\Lib\site-packages\pypng-0.0.13-py3.3.egg ?
    >
    > If not, you have not successfully installed pypng. Please try one of
    >
    > the methods I gave above.


    Yes I do have the egg.

    I'm gonna try to summarize:

    I don't have installations problems anymore but it seems that png.py is not run through 2to3 although it should since the setup.py is properly configured:

    if sys.version_info >= (3,):
    conf['use_2to3'] = True

    I even tried to skip the if to ensure the second line is executed but nothing changed.

    I don't know what I'm doing wrong but it seems that png.py is not properly translated to Python 3.
     
    , Oct 29, 2012
    #8
  9. Andrew Robinson

    Guest

    On Monday, October 29, 2012 3:48:09 PM UTC+1, Andrew Robinson wrote:
    > On 10/29/2012 06:39 AM, wrote:
    >
    > > That's very kind of you but I don't think it would be particularly fitted to my needs. The program I'm trying to code creates an image as an 2D array of "pixels" which is defined by RGBA value. My program needs to access and modifies every component of every pixels in the image following a set of rules, kind of like the game of life, only more complex.

    >
    > >

    >
    > > In fact I only need a library to "push" this array of pixels in a displayable format for the GUI and in PNG format to write the image to disk. I don't need to do any fancy stuff with the image, just being able to display and write it.

    >
    > >

    >
    > >

    >
    > Then, actually, what I am suggesting was *almost* perfect.
    >
    > To do transparency, you need to write the portable any map (PAM) formation.
    >
    >
    >
    > Simply print a text header to a file which says:
    >
    >
    >
    > P7
    >
    > WIDTH 10
    >
    > HEIGHT 10
    >
    > DEPTH 4
    >
    > MAXVAL 255
    >
    > TUPLTYPE RGB_ALPHA
    >
    > ENDHDR
    >
    >
    >
    > And then dump your 2D array to that same file.
    >
    > A very quick example in 17 lines of code:
    >
    >
    >
    > io = open( "anyname.pam","w")
    >
    > x,y = 10,10
    >
    > gray=(128,128,128,255) # R,G,B,A value
    >
    > picture = [ [ gray ] * x ] * y # Make a blank gray canvas 2D array
    >
    >
    >
    > # Do whatever you want to the 2D picture array here!
    >
    >
    >
    > io.write( "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE
    >
    > RGB_ALPHA\nENDHDR\n" % (x,y) )
    >
    >
    >
    > for yi in xrange( y ):
    >
    > for xi in xrange( x ):
    >
    > pixel = picture[yi][xi]
    >
    > io.write( chr(pixel[0]) ) # R value
    >
    > io.write( chr(pixel[1]) ) # G value
    >
    > io.write( chr(pixel[2]) ) # B value
    >
    > io.write( chr(pixel[3]) ) # A value
    >
    > io.flush()
    >
    >
    >
    > io.close()
    >
    >
    >
    > And that's it. You may of course make this more efficient -- I'm just
    >
    > showing it this way for clarity.
    >
    > Many programs can read PAM directly; but for those that can't you can
    >
    > use nettools, or imagemagick, to convert it to PNG.


    That's really interesting! Thank you so much! Never heard of PAM before... I will try that!
     
    , Oct 30, 2012
    #9
  10. Andrew Robinson

    Guest

    On Monday, October 29, 2012 3:48:09 PM UTC+1, Andrew Robinson wrote:
    > On 10/29/2012 06:39 AM, wrote:
    >
    > > That's very kind of you but I don't think it would be particularly fitted to my needs. The program I'm trying to code creates an image as an 2D array of "pixels" which is defined by RGBA value. My program needs to access and modifies every component of every pixels in the image following a set of rules, kind of like the game of life, only more complex.

    >
    > >

    >
    > > In fact I only need a library to "push" this array of pixels in a displayable format for the GUI and in PNG format to write the image to disk. I don't need to do any fancy stuff with the image, just being able to display and write it.

    >
    > >

    >
    > >

    >
    > Then, actually, what I am suggesting was *almost* perfect.
    >
    > To do transparency, you need to write the portable any map (PAM) formation.
    >
    >
    >
    > Simply print a text header to a file which says:
    >
    >
    >
    > P7
    >
    > WIDTH 10
    >
    > HEIGHT 10
    >
    > DEPTH 4
    >
    > MAXVAL 255
    >
    > TUPLTYPE RGB_ALPHA
    >
    > ENDHDR
    >
    >
    >
    > And then dump your 2D array to that same file.
    >
    > A very quick example in 17 lines of code:
    >
    >
    >
    > io = open( "anyname.pam","w")
    >
    > x,y = 10,10
    >
    > gray=(128,128,128,255) # R,G,B,A value
    >
    > picture = [ [ gray ] * x ] * y # Make a blank gray canvas 2D array
    >
    >
    >
    > # Do whatever you want to the 2D picture array here!
    >
    >
    >
    > io.write( "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE
    >
    > RGB_ALPHA\nENDHDR\n" % (x,y) )
    >
    >
    >
    > for yi in xrange( y ):
    >
    > for xi in xrange( x ):
    >
    > pixel = picture[yi][xi]
    >
    > io.write( chr(pixel[0]) ) # R value
    >
    > io.write( chr(pixel[1]) ) # G value
    >
    > io.write( chr(pixel[2]) ) # B value
    >
    > io.write( chr(pixel[3]) ) # A value
    >
    > io.flush()
    >
    >
    >
    > io.close()
    >
    >
    >
    > And that's it. You may of course make this more efficient -- I'm just
    >
    > showing it this way for clarity.
    >
    > Many programs can read PAM directly; but for those that can't you can
    >
    > use nettools, or imagemagick, to convert it to PNG.


    That's really interesting! Thank you so much! Never heard of PAM before... I will try that!
     
    , Oct 30, 2012
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leveridge Systems INC
    Replies:
    1
    Views:
    405
    red floyd
    May 13, 2004
  2. Active8
    Replies:
    4
    Views:
    2,320
    Active8
    Aug 31, 2004
  3. Replies:
    3
    Views:
    491
    Dieter Lamberty
    Aug 9, 2006
  4. los
    Replies:
    0
    Views:
    441
  5. Manuel Kasten
    Replies:
    1
    Views:
    109
    Joel VanderWerf
    Feb 2, 2006
Loading...

Share This Page