Forums

"ImportError:"... files in the same directory not finding said-file.

I've been trying to run a script that is located in my web application, just in a different folder than the actual web files.

Initially, I had a folder named "classes", which of course contained a class I need to use in my actual script file. It kept telling me that there is no module found. Then I put that class file in the same directory where the script file is, and now it is telling me "ImportError: attempted relative import with no known parent package".

I do not want to put the class file inside the script file, I feel there is a better way to do this.

This works perfectly on my own local server.

To import the files, I had this when it was in a different folder:

from classes.FileName import FileName

then when the files are in the same folder:

from FileName import FileName

I also tried:

from . import FileName

All giving me errors I do not see on my local server. So I'm guessing it might be something I'm doing wrong with PythonAnywhere servers.

Best,

Steve

We have a help page for this issue, see https://help.pythonanywhere.com/pages/DebuggingImportError/.