Search code examples
pythondjangogitbranchimporterror

ImportError for Nonexistent File in Django's Main Branch After Working on Separate Branch


I'm encountering an ImportError in my Django project involving branch management. Here's what I did:

  1. New branch: In a branch named test-new-spider, I created and committed a file named spider_base.py, which includes a class SpiderStores and a new command to run the spiders.

  2. Switching to Main Branch: After committing these changes in the test-new-spider branch, I switched to the main branch, which does not include the spider_base.py file, as the changes were not merged.

  3. Issue in Main Branch: Now, when trying to run the spider in the main branch, I encounter the following error: ImportError: cannot import name SpiderStores

This is confusing because spider_base.py does not exist in the main branch; it's only in the test-new-spider branch where it has been committed.

I deleted some files that were generated as eggs and logs, thinking they might be causing conflicts or stale references.

I disconnected from the virtual environment to ensure that there were no environment-specific issues contributing to the problem.

I searched for any instances of spider_base and SpiderStores in the main branch to confirm that it indeed doesn't exist there.


Solution

  • Delete any .pyc files in the folder. .pyc files can create this issue.

    It is also common practice to add .pyc files to the .gitignore file.