Forums

Importing files from other directories Flask App

Hello! I'm trying to import files from other directories, and the notes in the Debugging with sys.path/ImportError didn't really help me too much.

Locally, I'm able to access classes that are saved in files, that are saved inside different directories.

eg.

\ -- Directory1
\ -- \ -- File1.py
\ -- Directory2
\ -- \ -- File2.py

(in File2) from Directory1.File1 import Class.

Once I move the code to python anywhere, the compiler is unable to import 'Class'. from File1. Help?

Hi there,

If you go to your PythonAnywhere webapps tab, perhaps try setting the working directory to say \Directory1?

Thanks for the follow up conrad.

That wouldn't work in my case. I have a server file located at the root directory, and it references files that are in subdirectories of the root.

eg.

Root 
- / Directory1
     -/ File1
- / Directory2
    -/ File2
server.py

server.py would need to access the files located in Directory1 and Directory2. Is it possible to have more than one working directory?

Didn't realize the working directory wasn't already at the same place as the Directory1. Trying that now.

Changed the working directory, but I'm still getting the same error.

are you sure that's the error you are seeing? I took a look a look at your error log and it seems like it's a different error?

It was my error, but I couldn't figure it out so I just took the files out of directories and let them be free! Thanks for trying to help.

:D