[ERROR] FileNotFoundError: [Errno 2] on localhost

Hi guys,

This is my first Streamlit project.

I can run file fine on IDE (VS Code with path set to py file).
However, when running streamlit run on local host, I get FileNotFoundError: [Errno 2] No such file or directory:

I wasn’t able to deploy the app either, showing the same error back.

I checked many others’ deployed projects and find them writing the same relative path codes as I did (I was not able to run their py file on my Terminal either, same error)

My repo as follows, with MIT license:

Many thanks to anyone helping!

I usually just give the full file path when I call Streamlit run.

So something like

streamlit run "C:\Users\username\Documents\my_app.py"

I often run files on a server which is why I use the " "
I hope it helps!

Hey Luke, thanks for responding.

However, that is not the problem that I have.
Mine opens local host and just says FileNotFoundError: [Errno 2] No such file or directory:.

Streamlit clearly has trouble finding the files and I cannot figure out why :frowning:

Hey I just downloaded your code from github and it runs fine for me on localhost.

Are you using a virtual environment and did you activate it?

Hi Luke, thanks for helping.

That is interesting, I digged more into the problem, it seems to have to do with SSH. Still trying to figure the problem.

What do you mean by virtual environment?

1 Like

Oh I just mean where did you install python/streamlit.
I usually use Conda and install my packages in a new environment to avoid issues with package clashes.

But if everything is just installed in your default Python environment then I doubt it’s a virtual environment issue.

You can change environments in VS code too:

But I don’t know anything about SSL. So good luck!

I happened to not have conda and the dev environment definitely needed some tweeking.

Just another note, you are able to run my app, see it in local host, and delpoy it, right?

I can run it using

streamlit run SMO_app.py

And that serves the app on my local network. I can access it on any computer on my local network.

Mine opens local host

What do you mean by that? Your browser opens a URL like http://localhost:8502?
In response to what actions of yours exactly? What do you do to launch the app?

and just says FileNotFoundError: [Errno 2] No such file or directory:.

Who says that? The browser? The terminal?
Does the full error message not include a path? What is the traceback?

Hi, thanks for coming!

It means it can run on VS code ok, but once stream lit run in localhost,

It shows like this

Can I also add, it may be worth checking streamlit is installed correctly by opening your terminal and instead of run, you can try

streamlit hello

I am able to run the streamlit hello.

Another thing to note that if I change all directories to absolute, it runs fine. But then I cannot deploy the app on cloud :frowning:

Ah interesting. You should try to deploy it and see what happens. Maybe it is just your system.

Also, maybe you could add the base directory to your code like this:

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))

Then your directories would be something like

equipment_monthly_data = load_data(dir_path + '/datasets/monthly_cummulative_loss_count.csv').reset_index(drop=True)

This method is working locally, let me try deploying it and see what happens.

Many thanks for the help! I will let you know

1 Like

Now I get the error deploying the app, I did try link and unlink Github account on Streamlit, yet didn’t work.
Anything that I needed to do on Github’s side for account association?

Sorry, I’m not sure. I haven’t deployed apps online (usually I do apps for internal purposes at work).
Hopefully someone can help you

No problem, I am very thankful for your help already.

Best wishes!

1 Like

The reason was that I didn’t activate Streamlit clound account and ‘link’ with Github, thanks everyone!

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.