skip to Main Content

i am looking for a solution on how i make my .exe python file works well just like in visual studio code. After converting the python file into .exe, it wont run well as it shows traceback error. Traceback Error ..
Reconvert again with –onefile -w in cmd

Code:

from time import sleep
from newspaper import Article, Config
    import nltk
from newspaper.article import ArticleException, ArticleDownloadState

def get_News():
    while True: 
        print ("Enter URL: ")
        url = input('')
        print("n")
        user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0'

        config = Config()
        config.browser_user_agent = user_agent
        config.request_timeout = 10

        article = Article(url, config=config, lang='en')
        slept = 0
        article.download()
        article.parse()    

        title = article.title
        author = article.authors
        pub_date = article.publish_date
        text = article.text 

        article.nlp()

        print('Display Title, Author and Publish Date:')
        print(title ,author, pub_date)
        print ('n' +'Display Text from Article: ' + 'n' + text)
        print ('n' + 'Display Article Summary: ')
        print(article.summary)
        print('n')
        print('Display Keywords: ')
        print(article.keywords)

        if url == '':
            print('No URL Found. Exiting the Program...')
            break
        if __name__ == '__main__': 
        get_News()

I am using Visual Studio Code and to convert into .exe, i use py -m PyInstaller –onefile -.py

Thanks for your help and solutions !

2

Answers


  1. Chosen as BEST ANSWER

    Somehow i managed to solve it, seems like the newspaperarticle.py is not inside the file directory of my exe program. So i copy paste the newspaper folder from Python and paste it inside the file of my exe program and it finally worked.


  2. Please use command PyInstaller --onefile <filename> instead of yours. You are not writing a program with only UI, and -w means not using command window, which refer to stdin, stdout, stderr is invalid. And that means input(), print(), etc. is not available.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search