2

I have two Ubuntu VMs. On one of them, I can't seem to install PyGame. I've tried installing through various methods:

  • sudo apt-get install python-pygame
  • (Remove and reinstall pygame a couple times)
  • Building from source (also fails)
  • Using pip (also fails)

The core issue seems to be that when I import pygame with Python 2, I get No module named pygame error. (I get the same thing with Python 3, but I'm not trying to make this work with Python 3.)

I looked at various SO/SE/AU questions, including this one and a couple of others.

Is there a way to troubleshoot this deeper and/or resolve whatever the issue is? I would like to figure out how to get this working with apt-get.

On another similar VM, PyGame installs fine through apt-get.

Edit: The response to python -c 'import sys; print "\n".join(sys.path)' is the following, which is something I set up for MRuby ages ago (and need to nuke):

/home/ashiq/Desktop/my-android-toolchain/lib/python27.zip
/home/ashiq/Desktop/my-android-toolchain/lib/python2.7
/home/ashiq/Desktop/my-android-toolchain/lib/python2.7/plat-linux2
/home/ashiq/Desktop/my-android-toolchain/lib/python2.7/lib-tk
/home/ashiq/Desktop/my-android-toolchain/lib/python2.7/lib-old
/home/ashiq/Desktop/my-android-toolchain/lib/python2.7/lib-dynload
/home/ashiq/Desktop/my-android-toolchain/lib/python2.7/site-packages

Further edits: After deleting my-android-toolchain and removing it from the path (from .bashrc), I can import pygame.

ashes999
  • 177
  • 2
  • 10
  • If the two VMs are truly identical to each other, why would `apt-get` work on one and not the other? There must be some differences between them. – edwinksl Jun 20 '16 at 18:19
  • 1
    @edwinksl sorry, maybe "identical" is the wrong word. Both are Ubuntu 14.04 with similar virtual hardware. One has a lot more development use and tools installed than the other. The one with less use installs PyGame simply from `apt-get`. If I can't resolve this, I may just recreate a new Ubuntu VM to replace the dysfunctional one. – ashes999 Jun 20 '16 at 18:22
  • Please run `python -c 'import sys; print "\n".join(sys.path)'` and add the output to your question. – Byte Commander Jun 20 '16 at 18:34
  • 1
    The Python you are running is looking at odd places for its libraries. Did you install an additional Python version? Please add the output of `which python`. If you install Python packages using `apt` or `pip`, they will get installed for the default system Python, not for your custom one. – Byte Commander Jun 20 '16 at 18:41
  • @ByteCommander updated. I nuked my custom toolchain and it works. Please add an answer so I can accept/upvote it. – ashes999 Jun 20 '16 at 18:43

1 Answers1

2

Looks like you built or installed a custom Python in your home directory (~/Desktop/my-android-toolchain).

Probably this custom Python installation shadows the system Python. You can check which executable is getting run using the command

which python

It should report something like /usr/bin/python. This is the system's Python installation that is preinstalled and which is maintained by your package manager (apt).

If you use that to install Python packages or if you use this installation's pip, they will all install their modules in the system's Python installation. Anything there will not affect your custom Python installation in your home directory, as you see that it has only its own library paths.

You should either remove your custom my-android-toolchain Python installation or make sure that you are running the system's Python /usr/bin/python by default.

Byte Commander
  • 105,631
  • 46
  • 284
  • 425