Python Forum
Pyinstaller, a problem with bundling py file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pyinstaller, a problem with bundling py file
#8
(Jul-28-2018, 09:53 PM)Truman Wrote: ...and for this code it opens google map immediately instead of letting user to write an address and then opens it ( at least that's how I understand this code ).
It will close immediately when calling shell from a .exe generated bye these tools.
The trick is to use input() to stop it from close immediately.

Here some fixes and will show two version,one with sys.srgv and one with input().
# maps.py
import webbrowser, sys, pyperclip

def my_func(get_add):
    if len(sys.argv) > 1:
        address = ' '.join(get_add)
        pyperclip.copy(address)
        address = pyperclip.paste()
        input('Copied to clipboard,Enter to show in Browser')
        webbrowser.open(f'https://www.google.com/maps/place/{address}')
    else:
        print('Something went wrong')
        input('Enter to exit')

def test_it(args):
    print(args[1:])
    my_func(args[1:])

if __name__ == '__main__':
    test_it(sys.argv)
build with pyinstaller --onefile maps.py
With this one have to remember that work as sys.argv from command line.
So can not run the maps.exe bye doubleclick on it,have to give argument.
Output:
C:\code\dist λ maps.exe [] Something went wrong Enter to exit # With argument it work C:\code\dist λ maps.exe london ['london'] Copied to clipboard,Enter to show in Browser

# maps.py
import webbrowser, sys, pyperclip

def my_func(city):
    if isinstance(city, str):
        pyperclip.copy(city)
        address = pyperclip.paste()
        input('Copied to clipboard,Enter to show in Browser')
        webbrowser.open(f'https://www.google.com/maps/place/{address}')
    else:
        print('Something went wrong')
        input('Enter to exit')

def test_it():
    city = input('Enter name of city: ')
    my_func(city)

if __name__ == '__main__':
    test_it()
Build with pyinstaller --onefile maps.py
Now can doubleclick on maps.exe and shell will stay open till have entered city.
Reply


Messages In This Thread
RE: Pyinstaller, a problem with bundling py file - by snippsat - Jul-28-2018, 11:28 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020