11

In installed python-virtualenv, because this question said I should use virtualenv to install pygame. However, I'm not really sure how that's accomplished.

What I did (following these instructions):

virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3 --no-pip

And then I don't know where to go.

How do I install pygame to be used in the virtualenv?

Edit: I followed GuySoft's instructions, and everything installed great. However, when I tried import pygame in python3, I got the following error:

>>> import pygame
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/alden/.virtualenvs/pywork3/lib/python3.3/site-packages/pygame/__init__.py", line 95, in <module>
from pygame.base import *
ImportError: /home/alden/.virtualenvs/pywork3/lib/python3.3/site-packages/pygame/base.cpython-33m.so: undefined symbol: PyCObject_Check
ananaso
  • 3,890
  • 4
  • 30
  • 50
  • 1
    `src/pygame.h:75:20: fatal error: Python.h: No such file or directory` You probably need the Python development files. – Timo May 25 '13 at 19:22
  • Yeah, right at the beginning of the log I failed to notice that it warned about missing dependencies (including python3.3-dev), so I found the list on the pygame wiki and am installing them right now. – ananaso May 25 '13 at 19:27
  • @Timo I installed all the [recommended dependencies](http://www.pygame.org/wiki/CompileUbuntu#Python_3.x), but I'm still missing the jpeg dependency. Do you know what this would be? – ananaso May 25 '13 at 20:36

4 Answers4

14

I suggest you have pip in your virualenv, its useful.

Note: must have pygame's dependencies installed, you can find out what they are and install them with:

sudo apt-get build-dep python-pygame

Then try this:

rm -rf ~/.virtualenvs/pywork3 #clean what you have there
mkdir -p ~/.virtualenvs/pywork3
virtualenv --no-site-packages --distribute -p /usr/bin/python3.3 ~/.virtualenvs/pywork3
. ~/.virtualenvs/pywork3/bin/activate
pip install pygame
GuySoft
  • 774
  • 1
  • 7
  • 16
  • Just added an important step, tested and this should work :) – GuySoft May 25 '13 at 22:01
  • After I added the Source code repository, everything installed just fine; however, I ran into another error when I tried to import pygame, which I've added to the OP. – ananaso May 27 '13 at 21:53
  • That's a different issue. Pygame on python 3 is experiential. [Try following these instructions](https://plus.google.com/115566537842716428333/posts/HFQeyiKh3tZ) (aka download from source the latest version, and confirm you indeed have all the requirements). – GuySoft May 30 '13 at 16:32
  • Ok, will check that out. I also contacted the writer of the book to ask him about it. Thanks for the help! – ananaso May 30 '13 at 22:31
  • This doesn't seem to work any more. pygame isn't in the python packages repositroy. – Ben Davis Jul 05 '15 at 00:55
  • @BenDavis It is according to [Ubuntu package list](http://packages.ubuntu.com/utopic/python-pygame). Do you have universe repository enabled? – GuySoft Jul 05 '15 at 08:48
  • @GuySoft, that's the ubuntu package. It's not in the python package index (PyPI). – Ben Davis Jul 06 '15 at 17:55
1

that is working for me without problem:

sudo apt-get build-dep python-pygame

than:

pip install hg+http://bitbucket.org/pygame/pygame
A.B.
  • 89,123
  • 21
  • 245
  • 323
ThePhi
  • 275
  • 3
  • 13
  • Sad to report that this has ceased to work in ubuntu 15.10. The pip install just hangs. Attempting to download and install using "pip -e" shows missing libraries, which may be causing pip to fail silently. – lysdexia Dec 02 '15 at 22:02
  • I've been forced to to the usual "python ./setup.py install", then copy the results to my virtualenv. – lysdexia Dec 02 '15 at 22:17
1

I have found that pygame will not install in a virtualenv on ubuntu 15.10.

The problem is missing links to libswscale and libavformat.

On my system I added the following symlinks:

$ sudo ln -sf /usr/include/x86_64-linux-gnu/libswscale /usr/include/libswscale
$ sudo ln -sf /usr/include/x86_64-linux-gnu/libavformat /usr/include/libavformat

At that point I was able to follow the http://pygame.org/wiki/CompileUbuntu#Installing pygame with pip instructions. I am now levitating in a ball of clear light.

lysdexia
  • 111
  • 3
0

For pygame 2 (using SDL 2) with Python 3 on Ubuntu, you need to install the following dependencies (according to CompileUbuntu at pygame.org):

sudo apt-get install --yes libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libfreetype6-dev python3-setuptools python3-dev python3 libportmidi-dev

Then use pip to install pygame in your venv:

pip install pygame

A complete script could look like this:

$PYTHON_VENV_DIR=.venv

sudo apt-get install --yes python3-venv

# all these are required for pygame-2
sudo apt-get install --yes libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libfreetype6-dev python3-setuptools python3-dev python3 libportmidi-dev

python3 -m venv $PYTHON_VENV_DIR

source $PYTHON_VENV_DIR/bin/activate

python3 -m pip install --upgrade pip

pip3 install wheel
pip3 install pygame
leosh
  • 141
  • 4