Search code examples
pythonshellcmdpyinstaller

How to use os.system() inside a python executable file?


I need to run this command instagram-scraper "+ username +" --media-metadata --media-types none inside a python executable file as you see bellow is the code I'm using to do that and it's working fine when I run it like that py test.py, but after I turn it to an executable file using the PyInstaller command: pyinstaller -F test.py, it doesn't work and it doesn't return any error, the console disapears directly after execution.

import os

def getFollowers(username):
    os.system("instagram-scraper "+ username +" --media-metadata --media-types none")

getFollowers("oukebdane_med_anis")

Solution

  • After a long struggle, I finally found a solution to the problem, according to the strategy suggested by Mr. @AKX, whom I thank very much.

    import instagram_scraper as isc
    
    def getFollowers(username): 
        scraper = isc.InstagramScraper(usernames=[username], media_metadata=True, media_types=['none'])
        scraper.scrape()
    
    getFollowers("oukebdane_med_anis")
    

    NOTE: I tried to edit his answer to adapted to the correct solution but it says 'Suggested edit queue is full'