I have a setup.py script that builds an .app file on OS X, however I need to include pyusb which was installed with pip. It's located /Library/Python/2.7/site-packagespyusb-1.0.0a3-py2.7.egg I am able to use it within my application however when I try to build and run it it doesn't include this dependancy. My setup script looks like:
application_title = "software" #what you want to application to be called
main_python_file = "./src/main.py" #the name of the python file you use to run the program
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
includes = ["atexit","re"]
setup(
name = application_title,
version = "0.1",
description = "Description",
options = {"build_exe" : {"includes" : includes }},
executables = [Executable(main_python_file, base = base)])
I've seen an answer of adding pkg_resources to my includes but from what I have tried this has had no success. So what do I need to include pyusb in my application file.
Related
I had to to transform a module from .py to .pyd. I did it with Cython. I tested after the project, and everything worked fine. When I created a build with cx_Freeze, that .pyd module created problems. I can't understand why after building I get this ModuleNotFoundError.
File "tooth_comp.pyx", line 13, in int
src.graphics_dental_components.tooth_comp
ModuleNotFoundError: No module named 'graphics_utils.effects'
My setup script:
import sys
from cx_Freeze import setup, Executable
packages = []
excludes = []
include_files = ["assets", "views"]
build_exe_options = {"packages": packages, "excludes": excludes, "include_files": include_files}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "MyApp",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("app.py", base=base)])
The reason for the error message is because the application cannot find the extension.
Try adding graphics_utils.effects to the packages list then try recompiling.
If that does not work you could also try coping the module in the build folder manually.
I have a python script that I'd like to freeze. I made the cx_freeze script, and ran it. The .exe works well, but in the frozen script I open a .html file. When the file opens the webbrowser gives me the error "File not found: Firefox cannot find the file at /c:/blah/blah/blah/somefile.html"
As I understand it, this is because cx_freeze is confusing my OS between linux and Windows. However, I'm not sure this is it because I have the code
if sys.platform == "win32":
base = "Win32GUI"
In my setup file. Does anyone know what's going on?
My entire setup file is
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "someexe",
version = "0.1",
description = "someexe description",
options = {"build_exe": build_exe_options},
executables = [Executable("someexe.py", base=base)])
copied from the cx_freeze distutils page and edited to fit my needs.
Instead of using os.chdir('C:/path/to/dir'), you should be using os.chdir('C:\path\to\dir'). It's an error in your script, not your cx_freeze setup file.
I am using cx_Freeze to generate a windows binary for my PyQt app. But the binary installer that is generated seems to still contain references to files on MY machine. (The one that generated the binary). So I can't distribute the generated installer to other machines. When the program is launched on another machine it seems look for paths that only exist on my machine.
my setup.py looks like this:
import sys
from cx_Freeze import setup, Executable
""" To build on windows: python.exe setup.py bdist_msi """
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "Checkout",
version = "0.1",
description = "",
options = {"build_exe" : {"includes": "atexit"}},
executables = [Executable("checkout.py", base=base)])
Ok so I have python 3.2 installed and I have cx_Freexe 4.2.3 installed.
I have a folder called Python stuff. In this folder there are 2 files.
setup.py and holg.py (my application)
Here is my setup.py:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "holgame",
version = "0.1",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("holg.py", base=base)])
The next step I have been doing is Run > cmd:
python setup.py build
what I get is:
'python' is not recognized as an internal or external command, operable program or batch file.
I am only a beginner so I need clear steps. Maybe my programs should be in a different folder or something, I can't really be sure. Does anyone know what the problem is? Thanks
You either need to put Python on the Windows path, or you need to use an explicit path to python. Try:
$ \Python32\Python setup.py build
Here are some good instructions for getting Python installed on your Windows machine: https://openhatch.org/wiki/Boston_Python_Workshop_5/Friday/Windows_set_up_Python
You will first need to cd to the directory containing your code and setup.py. You should find a Windows command prompt tutorial to help with some of this basic stuff.
i'm writing an installer using py2exe which needs to run in admin to have permission to perform various file operations. i've modified some sample code from the user_access_controls directory that comes with py2exe to create the setup file. creating/running the generated exe works fine when i run it on my own computer. however, when i try to run the exe on a computer that doesn't have python installed, i get an error saying that the import modules (shutil and os in this case) do not exist. it was my impression that py2exe automatically wraps all the file dependencies into the exe but i guess that this is not the case. py2exe does generate a zip file called library that contains all the python modules but apparently they are not used by the generated exe. basically my question is how do i get the imports to be included in the exe generated by py2exe. perhaps modification need to be made to my setup.py file - the code for this is as follows:
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
)
Try to set options={'py2exe': {'bundle_files': 1}}, and zipfile = None in setup section. Python will make single .exe file without dependencies. Example:
from distutils.core import setup
import py2exe
setup(
console=['watt.py'],
options={'py2exe': {'bundle_files': 1}},
zipfile = None
)
I rewrite your setup script for you. This will work
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
#the options is what you fail to include it will instruct py2exe to include these modules explicitly
options={"py2exe":
{"includes": ["sip","os","shutil"]}
}
)