Chapter 7 #12
-
|
I am new to Python and therefore working through Head First Python. When I ran the final version of app.py in Chapter 7 I received a FileNotFoundError, specifically: File "/Users/name/Documents/python_work/Head First Python/webapp2/app.py", line 59, in show_bar_chart Thinking I may have made a mistake, I copied and pasted the code directly from this site, but it still resulted in the same error. All the correct files and folders appear to be in the web app directory, as advised in the book, so is it possible to advise me what is going wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 7 replies
-
|
Based on your output, it looks like your path might be the issue. You have "/Users/name/Documents..." - should that "name" value not be the same as your currently logged-in user-id? For instance, on my Mac, it would read "/Users/barryp/Documents..." i.e., not "name" as I'm logged in as user-id "barryp". Is this the issue? |
Beta Was this translation helpful? Give feedback.
-
|
Sorry, I changed my username from johnobrien to name for the purpose of the example (so my name was anonymous)!
… On 26 Feb 2025, at 16:37, Head First Python ***@***.***> wrote:
Based on your output, it looks like your path might be the issue. You have "/Users/name/Documents..." - should that "name" value not be the same as your currently logged-in user-id? For instance, on my Mac, it would read "/Users/barryp/Documents..." i.e., not "name" as I'm logged in as user-id "barryp". Is this the issue?
—
Reply to this email directly, view it on GitHub <#12 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BP4FXKIEMAUAFE66FW7MNUD2RXUUZAVCNFSM6AAAAABX5RMG72VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMZSHAZTIMY>.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
-
|
Good idea, here you go:

… On 27 Feb 2025, at 16:23, Head First Python ***@***.***> wrote:
Could I ask you to ZIP that folder, then attach the ZIP file to your reply. I'll then download and replicate your setup on my machine and see what I get. Thanks.
—
Reply to this email directly, view it on GitHub <#12 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BP4FXKNIWXY4YDBZAHAWE432R43YXAVCNFSM6AAAAABX5RMG72VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMZUGEZTONQ>.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
-
|
I’m having issues with the zipped files, as Github now advise that the zipped file is too big, so I have removed my web app folder working examples leaving the ‘clean’ webapp2 folder
Hope you can open this
… |
Beta Was this translation helpful? Give feedback.
-
|
Hi Paul
Yes, something weird is happening out there, as I unzipped the files before sending (check) and everything worked fine.
Please find attached the webapp2 folder, which (hopefully) includes app.py, swimclub.py and hfpy_utils.py

… On 28 Feb 2025, at 11:32, Head First Python ***@***.***> wrote:
I'm still not seeing it... so, just copy'n'paste your app.py, swimclub.py and hfpy_utils.py code into here and I can take a look at them. Not sure why GitHUB is making this so difficult.
|
Beta Was this translation helpful? Give feedback.
-
|
Just repeating a comment (in case you missed it): I'm just looking at the output from your session (above). Are you running your webapp from within VS Code (as that might be causing an issue)? Try this instead: Do a right-click on the webapp2 folder as shown at the bottom of the first column of your screengrab, then select "New Terminal at Folder" from the pop-up menu. This should open a Terminal window in your webapp2 folder. Now type python app.py to run your webapp directly from your OS, not from within the VS Code environment. What happens now? Also, if you want to use VS Code to run your webapps, be sure to open VS Code in the folder that your |
Beta Was this translation helpful? Give feedback.
-
|
Hi Paul
You are a genius!
Running the python app.py directly from the Terminal worked (except I had to enter python3 app.py).
Running VS Code from the terminal proved to be a bit trickier, as I am very much ‘inexperienced’, but eventually I determined that code cannot be called directly from the command line on a Mac without first installing the shell command. Once this was done the command code . also worked.
As you have very kindly persisted with my issue, I am a bit reluctant to push my luck and ask another question, but one issue remains outstanding so here goes:
Learning Python is proving to be a bit more tricky than anticipated, as somewhere along the line it seems that some knowledge of using the terminal and then HTML/SVG and then web development frameworks and then templating engines is also required. I understand why app.py ran directly from the Terminal, although I would not have known the code for this if you had not explained, but what I do not understand is why VS Code will not run unless it is run from the Terminal. The implication seems to be that it cannot find the files/folders, I am not sure whether this is a correct conclusion or not, but what is the issue and why is it happening? Surely everyone using your book will hit the same problem, as presumably we all expect VS Code to work flawlessly?
With many thanks
John
… On 1 Mar 2025, at 10:33, Head First Python ***@***.***> wrote:
Just repeating a comment (in case you missed it):
I'm just looking at the output from your session (above). Are you running your webapp from within VS Code (as that might be causing an issue)? Try this instead: Do a right-click on the webapp2 folder as shown at the bottom of the first column of your screengrab, then select "New Terminal at Folder" from the pop-up menu. This should open a Terminal window in your webapp2 folder. Now type python app.py to run your webapp directly from your OS, not from within the VS Code environment. What happens now?
Also, if you want to use VS Code to run your webapps, be sure to open VS Code in the folder that your app.py file resides in. To do this, open a Terminal window in your folder then type code . to instruct VS Code to open in the current folder which ensures your code in app.py can find the other folders (templates, data, etc.) relative to your app.py code.
—
Reply to this email directly, view it on GitHub <#12 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BP4FXKJVXN6DYZAHTO63DJ32SGEG5AVCNFSM6AAAAABX5RMG72VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMZVHE2TEMQ>.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
-
|
Hi PaulThanks for the explanation, it all makes sense, and I guess the lesson is to hereinafter systematically execute working folders from the Terminal!Many thanksJohnSent from my iPadOn 1 Mar 2025, at 15:31, Head First Python ***@***.***> wrote:
Hi John.
Glad to see it's working now, and there's no issues at all with asking extra questions. I'm always happy to help readers of my books. 😎
So... here goes:
Modern graphical UIs have taught everyone to double-click on a file and have that selected file open in its associated app. For instance, double-click on a DOCX file and Word opens. Double-click on a .XLSX file and Excel opens, and so on. Similarily, double-clicking on a .PY file opens your editor of choice, VS Code in this instance, with your Python code shown and ready for editing. This generally works well in that you can make changes to the file, save it, and the changes are then saved back to the same location that you double-clicked from. So far, so good.
However, an issue arises when you are opening a .PY file in order to execute it. In this case, the code is always executed relative to some predetermined working folder. When you run (in your case) python3 app.py or code . from an open Terminal window, both Python and VS Code use your current folder as their current working folder. If your code refers to a sub-folder (such as templates), that sub-folder is located relative to your current working folder and is, subsequently, found. Now... when you double-click on a .PY file and VS Code opens, you have no idea what VS Code's current working folder is... and it is very rarely the folder that contains your file. When you then try to run your code, any relative sub-folder locations no longer work as VS Code is NOT running from the folder that contains your code: it's running from somewhere else (and the folder it uses is typically OS-dependent and may well be your top-level HOME folder or - literally - anywhere else). When your app.py tries to look for templates, it cannot be found VS Code's current working folder isn't the one you're hoping it is (resulting in the sort of errors you were seeing) When you use python3 app.py or code . from an open Terminal window you control the folder your code runs from, which means there can never be any confusion (as you are in control).
Trusting that this helps. Feel free to ask further questions as needed. Cheers.
--Paul.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.

Just repeating a comment (in case you missed it):
I'm just looking at the output from your session (above). Are you running your webapp from within VS Code (as that might be causing an issue)? Try this instead: Do a right-click on the webapp2 folder as shown at the bottom of the first column of your screengrab, then select "New Terminal at Folder" from the pop-up menu. This should open a Terminal window in your webapp2 folder. Now type python app.py to run your webapp directly from your OS, not from within the VS Code environment. What happens now?
Also, if you want to use VS Code to run your webapps, be sure to open VS Code in the folder that your
app.pyfile resides in. To do this, open…