python distutils post msi installation - python

I am creating a msi installer with the distutils bdist_msi command. In my setup file,
i want to run a code after the msi has installed the package, please help..
from distutils.core import setup
from distutils.command.bdist_msi import bdist_msi
import os
import shutil
STARTMENU = "C:/ProgramData/Microsoft/Windows/Start Menu/Programs/ShotExplorer"
STARTUP = "C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Startup"
LINK = r"C:\Python27\Lib\site-packages\shotexplorer\ShotExplorer.lnk"
class MyCommand(bdist_msi):
def run(self):
bdist_msi.run(self)
print "Creating Start Menu Entries"
if not os.path.exists(STARTMENU):
os.makedirs(STARTMENU)
shutil.copy(LINK, STARTMENU)
shutil.copy(LINK, STARTUP)
setup(
name = "shotexplorer",
version = "1.0",
description = "Tool to explore shots on isilon",
author = "abhishek.garg",
author_email = "abhishekgarg12#yahoo.com",
packages = ["shotexplorer", "shotexplorer.pyHook"],
package_data = {"":["explorer.ico","quicktime.png","ShotExplorer.lnk","pyHook/_cpyHook.pyd"]},
include_package_data = True,
cmdclass = {'bdist_msi':MyCommand}
)

Related

How to include shared object files in wheel built from Poetry

I have a simple package that includes a C extension. I'm managing my dependencies and build process with Poetry.
When I run poetry build, the extension is compiled and included in the .tar.gz archive but not in the .whl and I don't understand why. Pip installing from the tar.gz archive works as expected but since the wheel is lacking the .so, pip installing the wheel results in an unusable package.
I've lifted the build machinery from here: https://github.com/python-poetry/poetry/issues/2740
pyproject.toml
[tool.poetry]
name = "python_ctypes"
version = "0.1.0"
description = ""
authors = ["Me"]
include = [
{path = "_extensions/*.so", format = "wheel"}
]
[tool.poetry.dependencies]
python = "^3.9"
numpy = "^1.22.1"
[tool.poetry.dev-dependencies]
[tool.poetry.build]
generate-setup-file = false
script = "build.py"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
build.py
"""Poetry build script for python_ctypes"""
import os
import shutil
from distutils.command.build_ext import build_ext
from distutils.core import Distribution
from distutils.core import Extension
from distutils.errors import CCompilerError
from distutils.errors import DistutilsExecError
from distutils.errors import DistutilsPlatformError
extensions = [
Extension("python_ctypes._extensions.arraysum", ["python_ctypes/_extensions/arraysum.c"]),
]
class ExtBuilder(build_ext):
# This class allows C extension building to fail.
built_extensions = []
def run(self):
try:
build_ext.run(self)
except (DistutilsPlatformError, FileNotFoundError):
print("Unable to build the C extensions")
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except (CCompilerError, DistutilsExecError, DistutilsPlatformError, ValueError):
print('Unable to build the "{}" C extension, '
"python_ctypes will use the pure python version of the extension.".format(ext.name))
def build(setup_kwargs):
"""
This function is mandatory in order to build the extensions.
"""
print(setup_kwargs)
distribution = Distribution({"name": "python_ctypes", "ext_modules": extensions})
distribution.package_dir = "python_ctypes"
cmd = ExtBuilder(distribution)
cmd.ensure_finalized()
cmd.run()
# Copy built extensions back to the project
for output in cmd.get_outputs():
relative_extension = os.path.relpath(output, cmd.build_lib)
if not os.path.exists(output):
continue
shutil.copyfile(output, relative_extension)
mode = os.stat(relative_extension).st_mode
mode |= (mode & 0o444) >> 2
os.chmod(relative_extension, mode)
return setup_kwargs
if __name__ == "__main__":
build({})

Problems with Cx_freeze

If I'm actually asking you for help, it's because I spend many hours for nothing into trying to fix my problem:
I would like to compile my python script into .exe:
(I am using Python 32 bits 3.1.4 and pygame)
I have 4 files: Class.pyc, _Class_game.pyc, _ressources.pyc et main.py
and a folder #ressources with all images and songs
This is my scritp setup.py:
import cx_Freeze
executables = [cx_Freeze.Executable("main.py"), base = "Win32GUI"]
cx_Freeze.setup(
name="Strike The square",
version = "2.0",
description = "Jeu Strike The Square, V2.1",
options={"build_exe": {"packages":["pygame"],
"include_files": ["_Class_.pyc","_Class_game.pyc","_ressources.pyc"]}},
executables = executables
)
This create a folder "exe.xin32-3.1" with python (compiled) and my game
Next, I use inno setup to build the installer and add the folder #ressources
On my computer, It works very well, but when one of my friend wants to play (he hasn't python and pygame), the game creates this error:
[Error][1]
Then...I think this error comes from windows' ressources but I don't know how can I fix it...
The option (in setup.py):
include_msvcr = True
Doesn't work...
Thanks for your answer and excuse my english...
Hawk_Eyes
PS: this my game imports
try:
import pygame,time, ctypes
from random import randint
from pygame.locals import *
from math import sqrt
from _ressources import Shared
except ImportError as e:
print("Erreur du chargement du module: {0}".format(e))
Not sure if this will help but this is a copy of my setup file, i have used this to compile Pygame, Pubnub and various things. notice i don't include the files i want to include. The setup auto finds the files needed.
import sys
from cx_Freeze import setup, Executable
exe = Executable(
script = r"launcher.py",
base = 'Win32GUI',
icon = None,
targetName = "launcher.exe"
)
setup(
version = "0.1",
description = "launcher",
author = "Joshua Nixon",
name = "launcher",
executables = [exe]
)
$ cd path/to/files
$ python file.py build
EDIT
I recently found you could create .MSI files using cx_freeze which are very nice for distributing. IF the program uses images then (because you cannot bundle images with the MSI (that i know of) you create a little function which downloads them on launch from imgur or some place))
setup.py for MSI
import sys
from cx_Freeze import setup, Executable
company_name = "JoshuaNixon"
product_name = "Test"
bdist_msi_options = {
'add_to_path': False,
'initial_target_dir': r'[ProgramFilesFolder]\%s' % (company_name),
}
if sys.platform == 'win32':
base = 'Win32GUI'
else:
base = None
exe = Executable(script='launcher.py',
base=base,
icon="mushroom.ico",
)
setup(name=product_name,
version='1.0.0',
description='blah',
executables=[exe],
options={'bdist_msi': bdist_msi_options})
$ cd path/to/files
$ python file.py bdist_msi

How To add icons to exe using Cx_Freeeze

I havs the setup.py file which is used to build my program. I wanted to know how to add an icon to the final exe
import sys
from cx_Freeze import setup, Executable
setup(
name = "Calculator",
version = "3.7.8",
description = "Simple Calculator",
executables = [Executable("Calculator.py", base = "Win32GUI")])
Just add icon=icon.ico in Executable() like this:
from cx_Freeze import setup, Executable
target = Executable(
script="Calculator.py",
base="Win32GUI",
compress=False,
copyDependentFiles=True,
appendScriptToExe=True,
appendScriptToLibrary=False,
icon="icon.ico"
)
setup(
name="Calculator",
version="3.7.8",
description="Simple Calculator",
author="Hanzalah Ravat",
options={"build_exe": options},
executables=[target]
)

Run time error with twisted and cx_freeze

I am currently trying to freeze some python code using twisted with cx_freeze.
I have this in my python file Main.py :
print('Start')
import twisted.internet
input('End')
and this in setup.py file :
import sys
from cx_Freeze import setup, Executable
includes = ["twisted.internet", "twisted.internet.protocol", "pkg_resources"]
excludes = []
packages = []
namespace_packages = ["zope"]
build_exe_options = {"packages": packages, "excludes": excludes, "includes": includes, "namespace_packages": namespace_packages, "append_script_to_exe":True}
base = None
#if sys.platform == "win32":
# base = "Win32GUI"
setup( name = "xxx",
version = "1.0",
author = "xxx",
author_email = "xxx",
description = "xxx",
options = {"build_exe": build_exe_options},
executables = [Executable("Main.py", base=base, icon = None)])
I keep getting a run time error R6034 when I run my compiled program. Someone knows why ?
In the end, I used a workaround. I figured out that the file zope.interface._zope_interface_coptimizations was the root of the issue (it fails to load) so I excluded it in my setup.py file :
excludes = ["zope.interface._zope_interface_coptimizations"]
It now works well but the initial problem is not solved and I fear I would need this package at some point.

Using CX_Freeze with Scipy: scipy.special._ufuncs.py

I am having problems freezing a programm of mine. I narrowed it down to the scipy module. The porgramm I am trying to freeze is:
from scipy import signal
signal.hann(1000)
My setup script is:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "Some name",
version = "1.0",
author="My name",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("Script_Name.py", base=base)])
# ^CHANGE THIS NAME!!!
Here is a picture of the error message. I also tried including scipy.signal in the setup file as
build_exe_options = {"includes":"scipy.signal"}
but it didn't do any good. Please help me.
I had a similar problem which could be solved by making sure that:
1 The build directory contains a file named _ufunc.pyd (instead of scipy.special._ufuncs.pyd as mentioned above). You can achieve this by specifying the build_exe_options:
build_exe_options = { 'packages': ['scipy'],
"include_files": [('path2python\\Lib\\site-packages\\scipy\\special\\_ufuncs.pyd','_ufuncs.pyd')]}
2 Making sure that all dlls used by ufunc.pyd are also in the build directory. In my case libifcoremd.dll adn libmmd.dll were failing. You can check this with dependencywalker
I hope this helps you out.

Categories

Resources