简体   繁体   中英

How to get Pyglet Working for Python 3?

I am excited to use Pyglet because of all its features, however I am having problems installing the latest development build of Pyglet on Python 3. I am aware people have already asked this question but none of the responses helped me at all.

UPDATE: What I mean is that I am unable to get Pyglet to install for Python 3, whenever I import Pyglet it showss an error message with some Python 2 code.

Install using the below command:

pip3 install pyglet

This worked for me.

Instead of installing pyglet you can also put a copy of pyglet in the project folder and import it from there. This approach makes it also easy to use different versions of pyglet for your projects.

To make pyglet running on python 3 you need to convert the latest version of pyglet using 2to3 . Without that conversion it will not run on python 3. With previous versions of pyglet you will have difficulties when trying to convert it so make sure to use 1.2 (which is currently at alpha state but quite stable).

I used:

    pip3 install pyglet

and it works perfectly. Make sure that when you run python from the terminal you use

    python3

and not

    python

because that messed it up for me at first.

The solution is to pip install from the rep, eg using

pip install -e hg+https://pyglet.googlecode.com/hg/@2813:0aa8bfe3313a#egg=pyglet

this is because the current version of pyglet in pip is not compatible with python 3 yet.

I applied the answer of @JC Leitão to Ubuntu 14.04.

sudo apt-get install python3-git mercurial
sudo pip3 install -e hg+https://pyglet.googlecode.com/hg/@2813:0aa8bfe3313a#egg=pyglet

And now I can import pyglet.

(However it seems to not work properly. If I run the hello world program the Hello world can not bee seen in the window. I can see just darkness in it.)

我认为这是因为您想将它与python3一起使用并且您正在使用pip安装它,这是针对python2的,pip3是针对python3的。

If you are installing using pip, try typing pip3 install pyglet and it will install for python 3 instead of python 2. (Any time you want to install for python3, use pip3 instead of pip)

If it is installed correctly, make sure you save the python file in the same folder that you have pyglet installed. If it is not installed and you don't have the path set up, it won't import.

If you have pip installed, then it should be easy, just use "pip install pyglet". Else install pip, it makes installing python packages a lot easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM