Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyglet 1.2alpha1 not working on Python 3.3.0

I can't use Pyglet 1.2alpha1 (which should be able to run under Py3) from Python 3.

I followed the instructions and installed it correctly, yet it doesn't run on Py3, but I know I installed everything right because I can use it from Python 2.7.

Every time I try to import piglet using the interpreter, I get this error:

>>> import pyglet

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./pyglet/__init__.py", line 276
    print '[%d] %s%s %s' % (thread, indent, name, location)
                   ^
SyntaxError: invalid syntax

Reading the errore message it's quite obvious that the error is in the print being written in Python 2 style (print foo instead of print(foo)).

So my question is: is it real that one can run pyglet under Python 3?

I know of people who use it correctly, so what should I do? May it be that there is a wrong version of Pyglet uploaded on the website? Should I convert it with 2to3?

like image 691
AndPassa Avatar asked Jan 19 '13 20:01

AndPassa


2 Answers

I have gotten Pyglet 1.2alpha1 to work on Windows 8 with Python 3.3.2. (The method should be the same on linux, aside from the different folder paths)

The problem is that when you run python setup.py install it will seem to hang for a long time after you see the first few lines following "skipping implicit fixer". If you then close the terminal/bash window (thus aborting the install process) and then run the setup.py again, it will skip 2to3 conversion and simply install the py2 source files.

The reason for the apparent "hang" is that it simply takes a while for 2to3 to convert the files, but if you wait long enough, the conversion will take place, and it will correctly convert and install the module.

If you have already installed this once, you will have to delete a few folders for the install to work properly.

First, delete the build folder in the 1.2alpha1 source folder: %unzip_folder%\pyglet-1.2alpha1\build (where unzip_folder is the folder where you unzipped the Pyglet 1.2alpha1 source)

Also delete the pyglet folder from the python Lib: %python%\Lib\site-packages\pyglet (where %python% is the python install folder, which defaults to C:\Python33 on Windows)

Then run python setup.py install. It should go through all the steps (copying files to build, converting using 2to3, and finally byte-compiling to the Lib subfolder).

like image 199
drwatsoncode Avatar answered Nov 09 '22 05:11

drwatsoncode


Pyglet 1.2 alpha is only "python3 ready" i.e. it won't run with python3 out-of-the-box but has to be converted via 2to3. (After the conversion it won't run with python2 anymore.)

To use pyglet with python2 and python3 projects I always copy pyglet into a subfolder of the project (and convert it with 2to3 if I want to use it with python3).

like image 25
Sebastian Avatar answered Nov 09 '22 04:11

Sebastian