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
#1
I tried to bundle my py to exe file by following this simple instruction:
http://www.pyinstaller.org/

after the second step I receive a looong output that ends with
Output:
AttributeError: 'str' object has no attribute 'items'
I also did pip install setuptools --upgradeand pip install six but after that receive the same error.

I use Notepadd++ with command prompt on Windows OS.
Reply
#2
is it code for python3 ?
Reply
#3
Now I see that created a dist subfolder with exe file that doesn't work.

this is a message for one of two codes that I tried to bundle:
[Image: fbj86d.png]

From some reason the other one doesn't have dist file open.

now I see that build folder is also created and again - exe files don't work.
Reply
#4
I tried also with updating requests module and it didn't help. Don't know what to do.

Is there any other compiler beside pyinstaller?
Reply
#5
start the exe from a terminal to see the error output.
Reply
#6
Can you post code you use?
Reply
#7
In the meantime I removed os.py file that I had in the same folder. Now exe file from dist folder opens command line but it close it after a moment. I see first print statement and 200.

code:
#! python3
# lucky1.py - Opens several Google search results.
  
import webbrowser
import bs4 
import requests
import sys
 
def my_func(search_str):
    print('Googling...') # display text while downloading the Google page
    url = 'http://google.com/search?q=' + ' '.join(search_str)
    print(f'url: {url}')
    res = requests.get(url)
    print(res.status_code)
  
    # Retreive top search result links.
    soup = bs4.BeautifulSoup(res.text, "html.parser")
  
    # Open a browser tab for each result
    linkElems = soup.select('.r a')
    for link in linkElems:
        print(f'link: {link}')
    numOpen = min(5, len(linkElems))
    for i in range(numOpen):
        webbrowser.open('http://google.com' + linkElems[i].get('href'))
 
def test_it(args):
    print(args[1:])
    my_func(args[1:])
  
if __name__ == '__main__':
    test_it(sys.argv)
	

#! python3
# mapIt.py - Launches a map in the browser using an address from the
# command line or clipboard.

import webbrowser, sys, pyperclip
def my_func(get_add):
    if len(sys.argv) > 1:
	    # Get address from command line
	    address = ' '.join(get_add)
    else:
	    # Get address from clipboard
	    address = pyperclip.paste()

    webbrowser.open('https://www.google.com/maps/place/' + address)
	
def test_it(args):
	print(args[1:])
	my_func(args[1:])

if __name__ == '__main__':
	test_it(sys.argv)
	
...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 looks that my codes are actually not designed to ask questions...If you have any advice what to look for please do.
Now I added input() but programs simply don't work after I add search term.
Reply
#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


Forum Jump:

User Panel Messages

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