How to create an exe file including folder strucure using pyinstaller?

46 views Asked by At

OS : Windows

Editor : VS code

Language : Python

====================

I'm writing a code that tells me the detailed location when I enter the name of the city.

I wrote as below using "recusive=True" option of "glob.glob", and it works correctly.

<Directory Structure>
D:\
└─WORLD
    ├─city.ipynb
    │
    ├─africa
    │  └─nigeria
    │      └─abuja
    │          └─lagos
    ├─asia
    │  └─republic_of_korea
    │      └─seoul
    │          └─gangnam
    ├─europe
    │  └─united_kingdom
    │      └─england
    │          └─london
    ├─north_america
    │  └─usa
    │      └─california
    │          └─los_angeles
    ├─oceania
    │  └─australia
    │      └─victoria
    │          └─melbourne
    └─south_america
        └─brazil
            └─sao_paulo
# city.ipynb

import glob

city_name = input("name : ")
city_dir = glob.glob(f'../world/**/*{city_name}*', recursive = True)
print(city_dir)

<Result> ['../world\\north_america\\usa\\california\\los_angeles']

Result

I made the code I wrote to distribute this file to others as exe file.

However, in order for that file to work correctly, the "world" folder must exist in the same directory as the "exe file".

It does not work properly when running as a single file (exe).

[0x216E914AABC] ANOMALY: meaningless REX prefix used
name : los_angeles
[]

To solve this problem, I modified "datas" in the "city.spec" file as below and then ran "pyinstaller city.spec".

# city.spec

a = Analysis(
    ['city.py'],
    pathex=[],
    binaries=[],
    datas=[('./north_america/*', './north_america')],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
)
PS D:\world> pyinstaller .\city.spec
1919 INFO: PyInstaller: 6.3.0
1920 INFO: Python: 3.10.11 (conda)
2408 INFO: Platform: Windows-10-10.0.19045-SP0
2415 INFO: Extending PYTHONPATH with paths
['D:\\world']
4479 INFO: Appending 'datas' from .spec
4481 INFO: checking Analysis
4512 INFO: checking PYZ
4537 INFO: checking PKG
4546 INFO: Bootloader C:\Users\jblue.jin\AppData\Local\aipforge\lib\site-packages\PyInstaller\bootloader\Windows-64bit-intel\run.exe
4546 INFO: checking EXE
PS D:\world>

But it still doesn't work properly with a single file (exe).

[0x216E914AABC] ANOMALY: meaningless REX prefix used
name : los_angeles
[]

How can I make it into a single file (exe) including the entire folder structure?

0

There are 0 answers