Sorry if this is a really stupid question,
How do I get the py2exe to find the module I wish to convert?
I keep getting this error:
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'dist_dir'
warnings.warn(msg)
running py2exe
creating C:\Users\David\workspace\setup\src\dist
*** searching for required modules ***
error: Pygame.py: No such file or directory
I looked up as many Pygame to .exe tutorials or problems others have had, but their problem seemed to occur AFTER they created a .exe file...
I can't even get it to create one.
I used the exact same code as the one found on http://pygame.org/wiki/Pygame2exe except that I changed:
class BuildeExe:
def __init__(self):
#Name of starting .py
self.script = "MyApps.py"
into
class BuildExe:
def __init__(self):
#Name of starting .py
self.script = "Pygame.py"
My Pygame.py exists in "C:\Users\"username"\workspace\pygame\src". Please help.
you can try putting this in a .py file:
from distutils.core import setup
import py2exe
setup(console=['hello.py'])
such as how they do in this tutorial. Then all you have to do is oppen up cmd.exe and cd to your "C:\Users\"username"\workspace\pygame\src" and type:
python setup.py py2exe
or you can changed the setup.py to whatever .py file you saved the above code in. (within the same directory as you gave)
Related
This question already has an answer here:
py2app-installed app using pygame fails
(1 answer)
Closed 1 year ago.
Title, I just finished my first pygame project which Is a very simple game with a main menu module and a main game module, they both run perfectly when I run them from sublime.
I tried using py2app to share this game with some friends, after installing py2app this is what I did in my terminal:
py2applet --make-setup MainMenu.py # (this module imports the main game module)
then I edited my setup.py file to include all my python files like images, sounds and fonts (this is the setup.py file):
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['MainMenu.py']
DATA_FILES = ['MySprite/Shoot/1.png','MySprite/Shoot/2.png',
'MySprite/Go/1.png','MySprite/Go/2.png','MySprite/Go/3.png','MySprite/Go/4.png','MySprite/Go/5.png','MySprite/Go/6.png','MySprite/Go/7.png','MySprite/Go/8.png',
'go_1.png','go_2.png','go_3.png','go_4.png','go_5.png','go_6.png','go_7.png','go_8.png','go_9.png','go_10.png','go_1L.png','go_2L.png','go_3L.png','go_4L.png','go_5L.png','go_6L.png','go_7L.png','go_8L.png','go_9L.png','go_10L.png','HomeScreen.png','icon.png','Bullet.png','SkyNight.png','GamePlatform.png','Heart.png','Starjedi.ttf','Chernobyl.ttf',
'MainMenu.wav','Fireball.wav','background.wav','Jump.wav','Zombie.wav','Hit.wav']
OPTIONS = {}
setup(
app = APP,
data_files = DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Then back to my terminal:
rm -rf build dist
then:
python setup.py py2app -A
which gave me an error so I changed it to python3 and it created a "build" and a "dist" folders, I tried opening the app inside the "dist" folder but it gave me an error and asked me to terminate or open the console, I right clicked on it and pressed show package options --> contents --> MacOs and pressed the file which opened another terminal with the error:
screen_home = pygame.image.load('HomeScreen.png')
FileNotFoundError: No such file or directory.
Both modules run perfectly from sublime, Im out of ideas and I tried googling the problem and I can't find a solution, Im new at this so I apologize if the solution was obvious or it was a dumb question and id appreciate any help.
I don't have a real answer but a few things to try and check:
We need to review a few things in the two lines, sometimes the setup.py requires to have the full path where each file is located, it is the right way, otherwise the setup.py will not find where are those images and it won't be able to include them into the final package, Are all those files in the same folder?, even if they are, try to add the full path for each file (jbsidis should be replaced by your username):
import os
APP = ['/home/jbsidis/Escritorio/MainMenu.py']
if os.path.isfile(APP[0])==True:
print("the MainMenu.py file it does exists")
DATA_FILES = ['/home/jbsidis/Escritorio/MySprite/Shoot/1.png','/home/jbsidis/Escritorio/MySprite/Shoot/2.png','/home/jbsidis/Escritorio/MySprite/Go/1.png','/home/jbsidis/Escritorio/MySprite/Go/2.png','/home/jbsidis/Escritorio/MySprite/Go/3.png','/home/jbsidis/Escritorio/MySprite/Go/4.png','/home/jbsidis/Escritorio/MySprite/Go/5.png','/home/jbsidis/Escritorio/MySprite/Go/6.png','/home/jbsidis/Escritorio/MySprite/Go/7.png','/home/jbsidis/Escritorio/MySprite/Go/8.png','/home/jbsidis/Escritorio/go_1.png','/home/jbsidis/Escritorio/go_2.png','/home/jbsidis/Escritorio/go_3.png','/home/jbsidis/Escritorio/go_4.png','/home/jbsidis/Escritorio/go_5.png','/home/jbsidis/Escritorio/go_6.png','/home/jbsidis/Escritorio/go_7.png','/home/jbsidis/Escritorio/go_8.png','/home/jbsidis/Escritorio/go_9.png','/home/jbsidis/Escritorio/go_10.png','/home/jbsidis/Escritorio/go_1L.png','/home/jbsidis/Escritorio/go_2L.png','/home/jbsidis/Escritorio/go_3L.png','/home/jbsidis/Escritorio/go_4L.png','/home/jbsidis/Escritorio/go_5L.png','/home/jbsidis/Escritorio/go_6L.png','/home/jbsidis/Escritorio/go_7L.png','/home/jbsidis/Escritorio/go_8L.png','/home/jbsidis/Escritorio/go_9L.png','/home/jbsidis/Escritorio/go_10L.png','/home/jbsidis/Escritorio/HomeScreen.png','/home/jbsidis/Escritorio/icon.png','/home/jbsidis/Escritorio/Bullet.png','/home/jbsidis/Escritorio/SkyNight.png','/home/jbsidis/Escritorio/GamePlatform.png','/home/jbsidis/Escritorio/Heart.png','/home/jbsidis/Escritorio/Starjedi.ttf','/home/jbsidis/Escritorio/Chernobyl.ttf','/home/jbsidis/Escritorio/MainMenu.wav','/home/jbsidis/Escritorio/Fireball.wav','/home/jbsidis/Escritorio/background.wav','/home/jbsidis/Escritorio/Jump.wav','/home/jbsidis/Escritorio/Zombie.wav','/home/jbsidis/Escritorio/Hit.wav']
for x in DATA_FILES:
if os.path.isfile(x)==True:
print("the "+str(x)+" file it does exists")
else:
print("the "+str(x)+" DOES NOT Exists in that location and that's why you got the error with your setup.py")
Here is the image in my case, my folders don't have those files, so the result is:
I'm trying to compile some project I've found on the web.
the project is wrapping some Fortran code into python object.
The author of that project wrote I need to run the setup.py file.
I've done that. It contains the following piece of code:
ext = Extension(name = "GaussianFitter._Fitter",
sources = ["GaussianFitter/src/lmdif.f",
"GaussianFitter/src/splev.f",
"GaussianFitter/src/gaussian.f90"],
and obviously all these "f" files are existing.
When I install that setup.py file it seams to do some job succesfully but the first line in the script which uses that _Fitter:
import _Fitter
doesn't work.
I'm newby with python, and have no experiment with Fortran at all, so please forgive my ignorance.
Edit: project available here:
https://github.com/ardiloot/GaussianFitter
Thanks!
Finally made it, so here's my for-begginers tutorial:
note - since it's for beginners - it sets all in the global scope.
install mingw32 from:
http://www.mingw.org/
Add it's bin path to system PATH.
add a setup.cfg file containing the following text:
[build]
compiler=mingw32
locate it in %pythondir%\Lib\distutils
since setup.py file contains links to .c or .f files (c++/fortran/c) in order to make command (python setup.py install) be able to locate these files - run the command when working directory (i.e. cd c:....\) is set.
Ignore red error line in code when you import that module. It is in the LIB directory, just try to run...
EDIT:
If still not managing to import the already built f files - building it in the following way might help:
python setup.py build_ext --inplace
which generates an object (*.pyd), this helped me after it, for any reason, stopped working.
I coded a python application with a GUI in Tkinter with pictures. Now that I have finished, I am trying to convert it to a .exe with py2exe. All my pictures are in the same folder as my python file and setup file, but when I try to convert my python file via the Command Prompt, I get error messages saying that my .ico file is not defined and that it can not copy it. I think the problem is due to my setup.py file. How do I allow my images to be copied into the new .exe executable file without getting errors I have never used py2exe before.
Setup file:
from distutils.core import setup
import py2exe
setup(console=['Gui.py'])
Error:
How do I fix this?
You may have just forgotten to define your icon:
cfg = {
'py2exe.icon':'icon.ico',
...
}
Try to change your setup.py like this:
from distutils.core import setup
import py2exe
data_files = [('', [r'standardicon.ico'])]
setup(
windows =['Gui.py'],
data_files = data_files
)
I have converted a python game I designed into an exe. Running the exe itself causes it to flash and then close, meaning an error has occured. Running it from the Command Prompt causes the error as well, but documents it:
Cannot load image: Playfield.png
Couldn't open images\Playfield.png
This is telling me that the load_image block is failing. I have encountered this before when I did not have an images directory.
I attempted to move the images folder to the dist directory. This is the error that shows up:
Traceback (most recent call last):
File "Table_Wars.py", line 728, in <module>
File "Table_Wars.py", line 51, in main
File "Table_Wars.py", line 236, in __init__
File "pygame\__init__.pyc", line 70, in __getattr__
NotImplementedError: font module not available
(ImportError: DLL load failed: The specified module could not be found.)
This is my first time with py2exe, so I'm not really sure what is happening. The raw python file itself, Table_Wars.py, runs as expected.
If it helps, the location for the entire Table_Wars folder is inside a folder called Games, located on my Desktop (C:\Users\Oventoaster\Desktop\Games\Table_Wars). I am running Windows 7 32 bit OS.
On request, here is the output.txt I have generated:
Folder PATH listing for volume OS
Volume serial number is 7659-4C9C
C:\USERS\OVENTOASTER\DESKTOP\GAMES\TABLE_WARS
build
bdist.win32
winexe
bundle-2.7
collect-2.7
ctypes
distutils
email
mime
encodings
logging
multiprocessing
dummy
pygame
threads
unittest
xml
parsers
temp
dist
images
Here is the setup.py I used to convert the file:
from distutils.core import setup
import py2exe
setup(console=['Table_Wars.py'])
EDIT: I have attempted to use the full py2exe example. This will create the exe, but gives the same Cannot load image error. Attempting to put the images folder in the same folder as the exe creates a Runtime Error: The application requested the runtime to terminate it in an unusual way.
The shortened form of the code Slace Diamond suggested prevents py2exe from finding Table_Wars.py:
from cmd:
running py2exe
*** searching for required modules ***
error: Table_Wars.py: No such file or directory.
setup and Table_Wars are in the same directory. If it help, I input the full path to python.exe and setup.py.
EDIT: I seem to be getting closer. I put the images directory within self.extra_datas, and now I am getting this:
Fatal Python error: (segmentation fault)
This application has requested the runtime to terminate it in an unusual way. Please contact the application's suppourt team for more information
When you build a distributable package with py2exe (and py2app for that matter), part of the package environment is to point to a local resource location for files. In your plain unpackaged version, you are referring to a relative "images/" location. For the packaged version, you need to configure your setup.py to include the resources in its own location.
Refer to this doc for very specific info about how to set the data_files option of your package: http://www.py2exe.org/index.cgi/data_files
That page has multiple examples to show both very simple paths, and also a helper function for finding the data and building the data_files list for you.
Here is an example of the simple snippet:
from distutils.core import setup
import py2exe
Mydata_files = [('images', ['c:/path/to/image/image.png'])]
setup(
console=['trypyglet.py.py']
data_files = Mydata_files
options={
"py2exe":{
"unbuffered": True,
"optimize": 2,
"excludes": ["email"]
}
}
)
This closely matches what you are trying to achieve. It is saying that the "image.png" source file should be placed into the "images" directory at the root of the resources location inside the package. This resource root will be your current directory from your python scripts, so you can continue to refer to it as a relative sub directory.
It looks like you've already fixed the image problem by moving the folder into dist. The missing font module, on the other hand, is a known problem between pygame and py2exe. Py2exe doesn't copy some necessary DLLs, so you have to override py2exe's isSystemDLL method, forcing it to include audio and font related DLLs.
If Table_Wars.py is the only module in your project, try running this script with python setup.py py2exe:
from os.path import basename
from distutils.core import setup
import py2exe
origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
if basename(pathname).lower() in ("libogg-0.dll", "sdl_ttf.dll"):
return 0
return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL
setup(windows=[{"script": "Table_Wars.py"}],
options={"py2exe": {"dist_dir": "dist"}})
You could also try the example py2exe setup file on the pygame wiki. If neither of them are working, please add the error messages to your question.
I tried running py2exe on a sample project, and it also breaks for me when I use the default pygame font. If you're using the default font, try putting a ttf file in the root of your project and also in the dist folder. You'll have to change the call to pygame.Font in your script as well:
font = pygame.font.Font("SomeFont.ttf", 28)
I tried to package a Twisted program with py2exe, but once I run the exe file I built, I got a "No module named resource" error.
And I found the py2exe said:
The following modules appear to be missing ['FCNTL', 'OpenSSL', 'email.Generator', 'email.Iterators', 'email.Utils', 'pkg_resources', 'pywintypes', 'resource', 'win32api', 'win32con', 'win32event', 'win32file', 'win32pipe', 'win32process', 'win32security']
So how do I solve this problem?
Thanks.
I've seen this before... py2exe, for some reason, is not detecting that these modules are needed inside the ZIP archive and is leaving them out.
You can explicitly specify modules to include on the py2exe command line:
python setup.py py2exe -p win32com -i twisted.web.resource
Something like that. Read up on the options and experiment.
Had same issue with email module. I got it working by explicitly including modules in setup.py:
OLD setup.py:
setup(console = ['main.py'])
New setup.py:
setup(console = ['main.py'],
options={"py2exe":{"includes":["email.mime.multipart","email.mime.text"]}})