Deploying python script that uses uncommon modules

Viewed 166

Suppose I have a python script that uses many uncommon modules. I want to deploy this script to sites which are unlikely to have these uncommon modules. What are some convenient way to install and deploy this python script without having to run "pip" at all the sites?

I am using python v3.x

2 Answers

pyinstaller with spec file would be an option. uncommon modules should be specified in hidden import parameters

pyinstaller [options] script [script …] | specfile

deployment arguments can be stored in spec file and pyinstaller can be executed with the entry python file as following command

pyinstaller start.py myscript.spec

sample spec file

block_cipher = None
a = Analysis(['minimal.py'],
     pathex=['/Developer/PItests/minimal'],
     binaries=None,
     datas=None,
     hiddenimports=[],
     hookspath=None,
     runtime_hooks=None,
     excludes=None,
     cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
     cipher=block_cipher)
exe = EXE(pyz,... )
coll = COLLECT(...)

see pyinstaller help for more details

You can create a python package with all the uncommon modules in your project and upload to a feed, could be public feed like www.pypi.org where all the pip installs are downloaded from or it could be your organizations azure devops artifacts.

After uploading your package, you only need to pip install from the feed that you have chosen.

Related