How to run pipreqs programatically inside python
Eboubaker opened this issue · 2 comments
Eboubaker commented
other libraries like pyarmor and pyinstaller allow you to launch the program from a python script.
example:
import PyInstaller.__main__
PyInstaller.__main__.run([
'--onefile',
'--windowed',
'main.py',
])
is equivalent to
pyinstaller --onefile --windowed main.py
How can I do this with pipreqs? We can't use the exec() function due to security reasons...
Eboubaker commented
ok i figured something
from pipreqs import pipreqs
from collections import defaultdict
args = defaultdict(lambda: None)
args['<path>'] = 'dist/'
args['--savepath'] = 'reqs.txt'
pipreqs.init(args)
pyinstaller_args = []
with open('reqs.txt', 'r', encoding='utf-8') as f:
needs = [n.split('==')[0] for n in f.readlines()]
Eboubaker commented
or i can just directly use get_all_imports which is what i need in this case
needs = pipreqs.get_all_imports('dist/')
for n in needs:
pyinstaller_args.append('--hidden-import=' + n)