#πŸ”’ FileNotFoundError Docker Container

55 messages Β· Page 1 of 1 (latest)

upper stratus
#

Hey, When I try to run a python script it yells at me with a "FileNotFoundError", when i do have the file.

slender oracleBOT
#

@upper stratus

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

upper stratus
#

Alive

nimble sierra
#

your process' "current working directory" isn't what you think it is

#
nimble sierra
#

so that's why it's not working

upper stratus
#

I saw the post, but am confused on what's going on here

nimble sierra
#

either change the current working directory, or change the path

upper stratus
#

I am a little bit confused on this

nimble sierra
#

did you read the link to the earlier discussion in discord?

upper stratus
#

i read the post

#

let me see

sonic rain
#

Could you show your dockerfile? It usually marks what is work directory and how your file is run. This will show us what cwd is.

Also, you can use __file__ to get the path of the current python file and then make paths relative to it.
Like using pathlib your file would be
pathlib.Path(__file__).resolve().parent / "blog/First-Blog.md"
(.parent because we want to get the directory where the py file is in)

hallow pasture
#

im curious abiut the overall setup here..
as when I do like a mysql db involved in a script, i spin up a mysql conatiner with a shared volume

upper stratus
hallow pasture
#

i see that now..

sonic rain
#

You said docker container but this is not the docker format pithink
I don't see any steps of creating it - copying source, installing dependencies, etc +where is the entrypoint?

hallow pasture
#

he might have some kind of dynamic parse for creating a docker compose yaml, not help seeing it in this format if so

upper stratus
#

this was the easy way apparently

patent tinsel
#

Is the os.getcwd printing the correct directory for you?

#

You could also try
./blob/First-Blog.md for the file path

What I would really recommend is doing a os.listdir on whereever you keep the file and see if it got copied

#

Something like

os.listdir("./blog")
upper stratus
patent tinsel
#

Have you tried adding a "./" to your filepath, assuming that is where blog comes from

patent tinsel
#

Does your self.filepath look like blog?

#

Try making that ./blog

upper stratus
patent tinsel
#

It should be
./blob/First-Blog.md

hallow pasture
#
import os

def print_dir_structure(path='.'):
    for root, dirs, files in os.walk(path):
        level = root.replace(path, '').count(os.sep)
        indent = ' ' * 4 * level
        print(f"{indent}{os.path.basename(root)}/")
        subindent = ' ' * 4 * (level + 1)
        for file in files:
            print(f"{subindent}{file}")

print_dir_structure()
#

this a nice snipet to get the dir structure for your repo, if your doing them

#

it may help in this case

upper stratus
upper stratus
#

This is super weird

hallow pasture
#

im confused, did you mean to ping me cause i dont see the output fromnthe func i gave you.. which you should runnat the start of the script to get the output.

upper stratus
#

It worked!

#

I just had to change the path to: /workspaces/portfolio-web/blog

#

Can somone explain the why of it now

hallow pasture
#

if your loik8ng in the folder blog, then thats how you map to it.
in all the screenshots you sent you were nit inclyding blog as a folder.

#

phone sheshh

upper stratus
#

who knows why, but it works

#

Maybe because i was using relative paths

slender oracleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.