The reference to a "city" is conceptual and not necessarily to be understood in the literal sense.
Whilst many commentators point to it in the context of Torah study like you mention (see Rashi, Torah Temimah and Ta'alumos Chochmah), the other approach is to see the notion of a "city" as being an end destination that a fool has neither the comprehension or intellectual capacity to locate.
For example, Ibn Ezra understands the pasuk as observing the failings of a fool. In essence, they are likened to a person who seeks to travel to a city but does not know the way. Thus, they spend their time on the road stumbling and wearying themselves without ever arriving at their end goal.
עמל. דמה הכסיל שיעמוד לבקש גדולות ונפלאות ממנו והוא לא ידע הנראות והידועות כאדם רוצה ללכת אל עיר ולא ידע הדרך וייגע ולא יראה חפצו
Toil - It compares a fool to one that seeks great and wonderful things from him and he lacks the proper knowledge/comprehension - like a man who want to go to a city and he does not know the way and will become weary and will not see his object (i.e. the final destination of the city).
In a similar vein, the Metzudas Dovid notes how the fool exerts a great deal of effort in things that they don't need to bother with. The imagery of the city brings this out, as he explains that rather than take a proper paved path to the city, he instead take a small and winding path which only results in him becoming overly exerted and exhausted.
In the Artscroll Tanach series on Koheles (p.107) it adds a point from Rav Saadiah Gaon:
On a philosophical level this verse refers to one who follows a system of thought and then abandons it because he has discovered some flaws in it. He transfers to another system and yet another, giving each one up in turn because something has made it reprehensible to him. Such a person may be compared to one who wishes to go to a certain city but does not know which road leads there; consequently he tries many roads." (Rav Saadiah Gaon)