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

No such file in directory & 'charmap' codec can't decode #715

Open
hfleitas opened this issue Feb 2, 2024 · 4 comments
Open

No such file in directory & 'charmap' codec can't decode #715

hfleitas opened this issue Feb 2, 2024 · 4 comments

Comments

@hfleitas
Copy link

hfleitas commented Feb 2, 2024

When trying the non-authoritative Python script to generate the measurements file at src/main/python/create_measurements.py.

PS C:\hiram_msft\1brc> & C:/Users/hiramfleitas/AppData/Local/Microsoft/WindowsApps/python3.11.exe c:/hiram_msft/1brc/src/main/python/create_measurements.py 1_000_000_000
Traceback (most recent call last):
  File "c:\hiram_msft\1brc\src\main\python\create_measurements.py", line 160, in <module>
    main()
  File "c:\hiram_msft\1brc\src\main\python\create_measurements.py", line 153, in main
    weather_station_names = build_weather_station_name_list()
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\hiram_msft\1brc\src\main\python\create_measurements.py", line 45, in build_weather_station_name_list
    with open('../../../data/weather_stations.csv', 'r') as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '../../../data/weather_stations.csv'

I copied the data folder & its contents to the root of the C:\ drive to retry but yet fails due to charmap error.

PS C:\hiram_msft\1brc> & C:/Users/hiramfleitas/AppData/Local/Microsoft/WindowsApps/python3.11.exe c:/hiram_msft/1brc/src/main/python/create_measurements.py 1_000_000_000
Traceback (most recent call last):
  File "c:\hiram_msft\1brc\src\main\python\create_measurements.py", line 160, in <module>
    main()
  File "c:\hiram_msft\1brc\src\main\python\create_measurements.py", line 153, in main
    weather_station_names = build_weather_station_name_list()
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\hiram_msft\1brc\src\main\python\create_measurements.py", line 46, in build_weather_station_name_list
    file_contents = file.read()
                    ^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 398: character maps to <undefined>
@GambitKZ
Copy link

I have fixed that by adding the encoding to read/write operations (45 and 118 lines accordingly):
with open('../../../data/weather_stations.csv', 'r', encoding="utf-8") as file:
and
with open("../../../data/measurements.txt", 'w', encoding="utf-8") as file:

@pgr-lopes
Copy link

Not sure if this is still being maintained, but this problem persists on my end even after those changes. I added the encoding reference using the io library and it seems to be working now. Example on line 45:

with io.open('../../../data/weather_stations.csv', 'r', encoding="utf8") as file:

@hfleitas
Copy link
Author

hfleitas commented Mar 25, 2024

I ended using WSL instead and the .sh commands in the instructions ran successfully, so I did not use the python unofficial script to generate the files.

Here's my gist (in-official submission results):
https://gist.github.com/hfleitas/060838e0e8eeb782dffead1de77ccd71#file-1brc-kql-L116

@Ale-Code404
Copy link

I got the same "No such file" error, but it worked when I ran it in the "src/main/python" directory.

cd src/main/python && python create_measurements.py 1_000_000_000

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

4 participants