Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run pipreqs programatically inside python #451

Closed
Eboubaker opened this issue Jun 10, 2024 · 2 comments
Closed

How to run pipreqs programatically inside python #451

Eboubaker opened this issue Jun 10, 2024 · 2 comments

Comments

@Eboubaker
Copy link

Eboubaker commented Jun 10, 2024

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
Copy link
Author

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
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant