ModuleNotFoundError with Flask app
I am trying to deploy a very simple Flask-React app to railway, but I keep getting this error :
This is my file structure : Image
This is my Dockerfile :
And this is my requirements.py :
Flask==2.3.2
Flask-Cors==3.0.10
Flask-SQLAlchemy==3.0.3
spacy==3.5.3
dateparser==1.1.8
I have tried using pip freeze to see the installed packages, and flask get's installed correctly, I am new to Flask apps, Dockerfiles and runway so I don't know how to solve this problem.
PS : the app does build but the app crashes in the deploy phase
111 Replies
Project ID:
6ecdf6a2-891e-42b8-a238-d0567de6cde3
6ecdf6a2-891e-42b8-a238-d0567de6cde3
share a link to your repo please
its private
now public
have you found anything ?
have some patients please, this is comunity support
Sure, I'm sorry
you used chatgpt lol
@Wapeto
show me a screenshot of your railway project
I did , as I said I'm new to Flask and Railway. What screenshot do you want exactly ?
a screenshot of your browser window open to the railway project
okay so since you have 2 services in a single repo, that is referred to as a mono repo.
and if you have two services in a repo, you need two services in your railway project
so lets only tackle one at a time
Okay...
What does it mean ?
remove your repo from that service
it will make sense in time, you just gotta follow what i say
How do I delete the repo from the service without deleting the service ?
in the service settings
found it
now rename that service to frontend
1. do you have any service variables set?
2. do you have a build command set?
3. do you have a start command set?
1. No
2. No
3. No
good
do you know how to merge a pull request on your repo?
normally
okay check your pull requests
should be done
you did this right?
yes
in the service settings, set the root directory to
/frontend
done
add your repo back
its building
yes
let me know how that goes
it failed
build logs please
Wait they seem cut of Im going to try redeploy
okay
Nah same thing hapened, this is the Build Log :
bruh
And then it crashes
^
I did
prove it
shit it didnt save or smth, my bad
lol
pic or it didn't happen
real
(jk i leave now)
where you going, we aint done
lol
oh god
Okay, it built correctly
This is the output from Deploy Logs :
How do I open the website now ? (or is there smth else to do before that)
youd need to generate a domain in the service settings
also big congratulations on not having build warnings, most people who have deployed react apps have a bunch of build warnings
I have this tho
did you generate a domain?
Thxx but it's really a basic app so there's that.
yes and this is the page it links me to
its still an accomplishment
send me the domain please
React App
Web site created using create-react-app
it works
My bad once again, Im sorry
no worries
Thanks soooo much, you're a wizard
okay backend time!!
oh
I had forgotten
What do I have to do ?
create a empty service in the same project and name it backend
And when everything is done, could you please tell me everything you did si I can solve the problem alone next time ?
okay
done
renamed and changed the root directory too
then set the root directory to /backend but make sure to save it this time
I made sure lmao
ah you getting the hang of this
okay i think you are good to add the repo
should I do something else ?
you need to generate a domain
Okay everything is done and running, but I have this error when I try using the app and make requests :
your app now needs to make requests to the backend domain of the railway service
ouhhh true
you are using sqlite right
but my backend keeps crashing
yup
show logs please
Okay I just checked and it's because I need the server to run :
python -m spacy download en_core_web_sm
somehwere
okay hold on
show me the table at the top of the build logs please
replace your railway.json file with this
you will also want to add the contents of this link https://www.toptal.com/developers/gitignore/api/python to a
.gitignore
file in your backend, and delete the __pycache__
folder in the repoThxx, sorry if Im not answering I'm dealing with the routes errors not, even though I changed the routes to the backend domain, it still sends requests to localhost:5000
you have it hard coded somewhere
My bad I was mistaken about the error, it's just that the search feature returns this error now :
And the code this comes from is the SearchInput.js :
Where results is set
you need to be using https
My bad
your backend needs to have a cors origin for
abnar.up.railway.app
https://flask-cors.readthedocs.io/en/latest/I have this :
should i add a ressource ?
what is something i could search for with your api
show me the deploy logs for the backend
Well it's just some kind of memory, you input some text, when you save it labels it, and when you type some keywords in the searchbar, the most relevant texts shoudl show up
^
I'm sorry the error for the crash was my fault, it's solved now and the backend logs are empty :
do you actually use a sqlite database?
I do, this is were the texts and tokens are saved
normally...
because railway doesn't have persistent storage, so on every deploy your sqlite database gets wiped
you will want to use a database railway provides as a plugin
okay
have fun!
Thanks a lot for your help ! You are the proof humans are still smarter than machines (I spent 2 days on this problem and chatGPT cound't find any working solutions)
add a database of your choosing (use postgre)
setup the variable references https://docs.railway.app/develop/variables#reference-variables
use those variables in your code along with whatever postgre library you want
Will I still be able to run the project locally ?
i only know you used chatgpt because you had a railway.yml file, railway has never used a railway.yml file for anything
Well... It also made me create a whole lot of different Dockerfiles and other things
you will now run your app with
railway run <your regular start command here>
so that your app will have access to the database variables
oh yeah that dockerfile was horrendousin my local terminal I would type :
railway run npm start ?
your frontend does not need the database variables, so you start that normally, your backend needs the database variables so you would use
railway run <blah blah>
to start your backendokay thx a lot for that, one last question if I may ?
sure
This is how I created my original database in python
But I don't see the option for the label row in the postgre ui on railway
labels would be lists of strings
now thats a question for google, i dont do too much with databases myself
Okay no problem, once again thanks for your help and time, you really saved me there
no problem 🙂