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

MapView and MacOS PyInstaller Python 3.10 - package App Crash at startup #62

Open
Paullux opened this issue Dec 28, 2022 · 2 comments
Open

Comments

@Paullux
Copy link

Paullux commented Dec 28, 2022

Describe the bug
If I tried to compile my application to an app package for macOS with PyInstaller, the app crash at startup.

With the same code where i don't add the Mapview, the app don't crash.

Also in my IDE or if I am entering in app package and i am trying to launch the exec file the app is launched.

I can write in my folder tmp_dir with the app before the crash without problem.

To Reproduce

the code with crash

class RootWidget(FloatLayout):

    def __init__(self, **kwargs):
        # make sure we aren't overriding any important functionality
        super(RootWidget, self).__init__(**kwargs)

        # random position
        Nord  = 51.08916667 
        Sud   = 42.33277778
        Est   =  8.23055556
        Ouest = -4.79555556
        random_latitude = random.uniform(Sud, Nord)
        random_longitude = random.uniform(Ouest, Est)
        
        # let's add a Widget to this layout
        self.tmp_dir = os.getenv("HOME") + '/Library/Low-Fuel/'
        if not os.path.exists(self.tmp_dir):
            os.makedirs(self.tmp_dir)

        self.mapview = MapView(lat=random_latitude, lon=random_longitude, zoom=12, map_source="osm", size_hint=(1, 1), cache_dir=self.tmp_dir)
        self.add_widget(self.mapview) 
        
class Low_Fuel(App):
    def build(self):
        self. Title = 'Low-Fuel'
        if hasattr(sys, '_MEIPASS'):
            self.icon = '../Resources/petrol_pump.icns'
        else:
            self.icon = 'image/petrol_pump.icns'
        self. Root = RootWidget()

if __name__ == '__main__':
    Low_Fuel().run()

the code without crash

class RootWidget(FloatLayout):

    def __init__(self, **kwargs):
        # make sure we aren't overriding any important functionality
        super(RootWidget, self).__init__(**kwargs)

        # random position
        Nord  = 51.08916667 
        Sud   = 42.33277778
        Est   =  8.23055556
        Ouest = -4.79555556
        random_latitude = random.uniform(Sud, Nord)
        random_longitude = random.uniform(Ouest, Est)
        
        # let's add a Widget to this layout
        self.tmp_dir = os.getenv("HOME") + '/Library/Low-Fuel/'
        if not os.path.exists(self.tmp_dir):
            os.makedirs(self.tmp_dir)

        #self.mapview = MapView(lat=random_latitude, lon=random_longitude, zoom=12, map_source="osm", size_hint=(1, 1), cache_dir=self.tmp_dir)
        #self.add_widget(self.mapview) 
        
class Low_Fuel(App):
    def build(self):
        self. Title = 'Low-Fuel'
        if hasattr(sys, '_MEIPASS'):
            self.icon = '../Resources/petrol_pump.icns'
        else:
            self.icon = 'image/petrol_pump.icns'
        self. Root = RootWidget()

if __name__ == '__main__':
    Low_Fuel().run()

Expected behavior

Can open the App and distribute my app

Logs/output

The macOS console give this :

	Traceback (most recent call last):
	  File "main.py", line 313, in <module> <- the App Loop
	  File "kivy/app.py", line 955, in run
	  File "kivy/base.py", line 574, in runTouchApp
	  File "kivy/base.py", line 339, in mainloop
	  File "kivy/base.py", line 379, in idle
	  File "kivy/clock.py", line 733, in tick
	  File "kivy/clock.py", line 776, in post_idle
	  File "kivy/_clock.pyx", line 620, in kivy._clock.CyClockBase._process_events
	  File "kivy/_clock.pyx", line 653, in kivy._clock.CyClockBase._process_events
	  File "kivy/_clock.pyx", line 649, in kivy._clock.CyClockBase._process_events
	  File "kivy/_clock.pyx", line 218, in kivy._clock.ClockEvent.tick
	  File "kivy_garden/mapview/view.py", line 768, in do_update
	  File "kivy_garden/mapview/view.py", line 880, in load_visible_tiles
	  File "kivy_garden/mapview/view.py", line 893, in load_tile
	  File "kivy_garden/mapview/view.py", line 907, in load_tile_for_source
	  File "kivy_garden/mapview/source.py", line 212, in fill_tile
	  File "kivy_garden/mapview/downloader.py", line 37, in instance
	  File "kivy_garden/mapview/downloader.py", line 52, in __init__ <- this is the point which create the crash
	  File "os.py", line 225, in makedirs
	OSError: [Errno 30] Read-only file system: 'cache'

in line 52 in mapview/download.py try it to write in app package

Platform (please complete the following information):

  • OS: MacOS 13.1 Ventura with M1 proc
  • Python version 3.10
  • I tried with release and git last: branch / last:commit the error it always the same.

Additional context
my plist configuration with the access i need

    info_plist={
        'NSPrincipalClass': 'NSApplication',
        'NSAppleScriptEnabled': False,
        'Privacy - Documents Folder Usage Description': "This application requests access to the user's Documents folder.",
        'NSDocumentsFolderUsageDescription': "This application requests access to the user's Documents folder.",
        'Application is background only': False,
        'AllowCacheDelete': True,
        'AllowPersonalCaching': True,
        'CFBundleDocumentTypes': [
            {
                'CFBundleTypeIconFile': 'petrol_pump.icns',
                'LSItemContentTypes': ['com.lowfuel.bitscripts'],
                'LSHandlerRank': 'Owner'
            }
        ]
    }
@Paullux
Copy link
Author

Paullux commented Dec 29, 2022

i found a solution :
change mapview/constants.py
Capture d’écran  cache
to
Capture d’écran  os getenv( HOME ) +  Library-mapview

@subhashsharma
Copy link

subhashsharma commented Mar 3, 2024

Or change it to this:
from os import path, getenv
root = getenv('EXTERNAL_STORAGE') or path.expanduser("~")
CACHE_DIR = path.join(root, "Documents", "cache")

This is in the package mapview/constants.py

The above fix works form me in the iOS device

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

2 participants