Giter VIP home page Giter VIP logo

Comments (4)

gboeing avatar gboeing commented on June 12, 2024

What happens when you run:

import sys; print(sys.getfilesystemencoding())
import locale; print(locale.getpreferredencoding())

Is your OS set to use utf-8 for both of those encodings?

I thought Python on all platforms was defaulting to utf-8 since like 3.6 (see PEP 528 and 529)... but maybe it's somehow still opt-in on Windows (see PEP 540)?

from osmnx.

gboeing avatar gboeing commented on June 12, 2024

Here's another test for you:

from pathlib import Path
with Path("kaliningrad.xml").open() as f:
    print(f)

The file is encoded as utf-8 and the XML declaration states that it is utf-8... does your system open it with utf-8 encoding or does it print some other encoding instead?

from osmnx.

jonnyhuck avatar jonnyhuck commented on June 12, 2024

Thanks Geoff,

Interesting, those tests are quite revealing:

import sys; print(f"File System Encoding: {sys.getfilesystemencoding()}")
import locale; print(f"Preferred encoding: {locale.getpreferredencoding()}")
from pathlib import Path
with Path("./data/kaliningrad/kaliningrad.xml").open() as f:
    print(f)

...gives...

File System Encoding: utf-8
Preferred encoding: cp1252
<_io.TextIOWrapper name='data\\kaliningrad\\kaliningrad.xml' mode='r' encoding='cp1252'>

which is clerly the source of our problem!

This error came up as part of a practical for a course at the University of Manchester - we have been running it for years and this is the first time that this has happened, I am not sure what has changed to cause it (we are seeing it across all Windows machines that we have tried, not just a particular build etc.). I guess that this sort of thing might be part of the motivation behind PEP686, which sems to suggest that Python will override the locale settings to UTF-8 by default from version 3.15.

Nevertheless, adding an encoding argument to the function as you have seems like an ideal solution - thanks for dealing with it so quickly.

from osmnx.

gboeing avatar gboeing commented on June 12, 2024

Great, I'll merge that PR and dream of the day when Python 3.15 arrives 🥳

from osmnx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.