I'm having some trouble getting importing stuff from another class, I think I may be doing it wrong.

I have a simple main class called Test and at the top I say:

from WordFixer import WordFixer
import sys

Then in the same folder (the src folder) I have a file called and it's heading says:

class WordFixer:

but I'm getting an error in Test that says "Unresolved import: WordFixer"

What am I doing wrong?

Dani AI

Generated

Short answer: that “Unresolved import” is usually an IDE lookup problem rather than a Python runtime problem. What experienced — the warning disappearing after commenting/uncommenting — is exactly what happens when the editor re-indexes the project. was right to look at the path, and / touched on an important point: a “module” can be either a single .py file or a package folder.

Checklist to resolve and avoid this in the future:

  • Confirm the module file actually lives on the project source path and that the import name matches the filename exactly (case matters on case-sensitive filesystems).
  • If the code runs from the command line but Eclipse shows a warning, refresh the project and force a rebuild (right‑click → Refresh; Project → Clean). That clears stale analysis caches.
  • Make sure Eclipse/PyDev knows your source folder: Project → Properties → PyDev - PYTHONPATH (add the folder if missing). Also check the interpreter under Window → Preferences → PyDev → Interpreters.
  • If the code is inside a package, ensure package structure is correct for your Python version (init files for older versions) and use the appropriate absolute or relative imports.
  • Watch for name collisions (module named the same as a stdlib module) and for circular imports; both can produce confusing import errors.

If the import still fails at runtime (not just a warning), run the script from a terminal to capture the actual ImportError traceback — that tells you whether it’s a path problem, a missing file, or a circular import. Restarting Eclipse after adjusting PYTHONPATH or the interpreter often finishes the fix.

Recommended Answers

All 5 Replies

Well it seems to work now although I'm not sure why...I commented out the line and uncommented it a little bit later. I'm using eclipse. Maybe I should have forced it to compile or something.

Sometimes, if the module isn't in the same place, it is a matter of the path. At the begging of your progam you can do something like:

import sys
sys.path.append('/path/tomy/module')
from MyMod import moduleA

However I don't know how Eclipse as an IDE differs in terms of working directory...

sys.path.append('/path/tomy/module')

module is a file or folder ?

either

I guess ungalcrys has left Python a long time ago.
This is his only post over 4 year ago,look at dates.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.