Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying python script that uses uncommon modules

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

like image 947
user1315789 Avatar asked Nov 21 '25 05:11

user1315789


1 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

like image 119
oetzi Avatar answered Nov 22 '25 18:11

oetzi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!