Reputation: 25
I started to learn Python last week. I am newbie with not much coding experience.
I created a "Space Invader" game using Pygame (installed in my virtual environment) and it works perfectly when I launch it with Python2.7 as
python myfile.py
However if I launch it as
python3 myfile.py
I have a Traceback error
ImportError: No module named 'pygame'
Cool I can deal with it, even if I don't know why. However when I use pyinstaller myfile.py
, it converts the program into stand-alone executables using Python3
115 INFO: PyInstaller: 3.2
115 INFO: Python: 3.5.0b4
125 INFO: Platform: Darwin-15.5.0-x86_64-i386-64bit
126 INFO: wrote mydir/myfile.py
and therefore the same error when I launch the app. I am working on a Mac OSX El Captain.
The questions are: Why it does not work on Python3? How do I use 'pyinstaller' with Python2.7?
All the explanations about package management with a "human" language are welcome.
P.S. I tried cx_Freeze and bbFreeze but I always end up with the following error. I have a Mac OSX El Captain.
OSError: [Errno 1] Operation not permitted: '/mydir/MacOS.so'
Upvotes: 1
Views: 3267
Reputation: 5784
Python libraries are installed separately for Python 2 and Python 3. Looks like you have pygame
installed only for Python 2. Regular pip install [package]
only installs the Python 2 version in most setups. In general, everything considers Python 2 the "default" version for some reason, including the other major Unix-based OSs.
First, activate your virtualenv (source ./bin/activate
in the venv directory).
pip3 install hg+http://bitbucket.org/pygame/pygame
(or maybe pip-3.5
) in your virtualenv should fix it.
If it complains about hg
not being found, install Mercurial somehow (e.g. sudo port install mercurial
if you have MacPorts).
Try it out. Run python3
, then put import pygame
.
Sources:
import pygame
.Upvotes: 2