R
Railway13mo 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
Percy13mo ago
Project ID: e4949be4-03c7-44a7-a413-32ffc2e9c2f7
nova
nova13mo ago
e4949be4-03c7-44a7-a413-32ffc2e9c2f7
Brody
Brody13mo ago
is the required module in your requirements.txt file?
nova
nova13mo ago
the required module is actually my own module, but in a different directory
Brody
Brody13mo ago
then just use relative paths
nova
nova13mo 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
Brody13mo ago
definitely shouldn't be doing this, even locally again, use relative paths
nova
nova13mo ago
is there any way to do it with absolute paths?
Brody
Brody13mo ago
the word "relative" comes to mind
nova
nova13mo ago
@Brody
Brody
Brody13mo ago
#🛂|readme #5
nova
nova13mo ago
my bad sorry
nova
nova13mo 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.