R
Railway15mo ago
nova

How to figure out what my PYTHONPATH environment variable should be

I am getting a ModuleNotFoundError: No module named. I do not have this problem when running the applicaiton through Pycharm or through the terminal. I believe I have it in railway, because the sys.path on Railway is different from that on my own machine. How do I figure out the directory dtructure in a deployed railway application so I can modify the PYTHONPATH environment variable in Railway.
13 Replies
Percy
Percy15mo ago
Project ID: e4949be4-03c7-44a7-a413-32ffc2e9c2f7
nova
nova15mo ago
e4949be4-03c7-44a7-a413-32ffc2e9c2f7
Brody
Brody15mo ago
is the required module in your requirements.txt file?
nova
nova15mo ago
the required module is actually my own module, but in a different directory
Brody
Brody15mo ago
then just use relative paths
nova
nova15mo ago
My Project/ ├─ utils/ │ ├─ new_file3.py │ ├─ new_file2.py │ ├─ new_file.py ├─ Fast API/ │ ├─ main.py Imagien this is my directory structure I want to be able to import new_file into my main app it works on my machine if I add my project to sys.path but not on railway
Brody
Brody15mo ago
definitely shouldn't be doing this, even locally again, use relative paths
nova
nova15mo ago
is there any way to do it with absolute paths?
Brody
Brody15mo ago
the word "relative" comes to mind
nova
nova15mo ago
@Brody
Brody
Brody15mo ago
#🛂|readme #5
nova
nova15mo ago
my bad sorry
nova
nova15mo ago
btw for anyone looking at this in the future with the same error what I did instead was to set the project root as the outermost directory and use the following "start command" uvicorn api.fast_api.main:app --reload --host 0.0.0.0 --port $PORT I didn't know that you can run a uvicorn application similar to how you run a python module with the . syntax This allowed me to continue to use absolute imports as I was getting errors with relative imports.