Unresolved Reference Errors for django
Hi there – I've been using PyCharm for a while without any issues, but today I'm running into unresolved reference errors for django in my all my files and I can't figure out why.
More info:
I'm starting to think it might be an issue with how I have the project set up, either the directory structure or maybe the fact that I'm using multiple settings files.
As far as the directory structure goes, I have a top-level directory that is my git repo root. Within that I have requirements.txt. Then inside that directory (i.e. a directory at the same level as requirements.txt) I have the root of the Django project – here's the high-level layout:
foo-project
requirements.txt
foo
foo
settings.py
settings
base.py
local.py
production.py
staging.py
manage.py
This is the project layout proposed in Two Scoops of Django if you're familiar with that book.
As far as how I fired this up as a project in PyCharm, I did File -> Open Directory and pointed to the root of the git repo as opposed to the root of the Django app itself.
So my first question is, and this may be at the heart of the unresolved reference error, why is PyCharm insisting that I don't have my package requirements satisfied when I do? Would that cause the unresolved reference errors? Do I need to move my requirements.txt file elsewhere, or is there a way to point PyCharm directly to it?
My second question is if this is related to the fact that I'm using multiple settings files? Each of the environment-specific settings files imports everything from the base file (from .base import *). In the PyCharm Python interpreter settings for this project I added –settings=foo.settings.local in the Additional options box. And when I launch the app from PyCharm, it very clearly says "Django version 1.5.1, using settings 'foo.settings.local'" in the console.
Note that I have not run into this issue in projects with the requirements.txt file in the same directory as manage.py and in which I use a single settings.py file, but before giving up on what I think is a much better project structure I figured I better ask what might be going on here.
Happy to provide more information to help troubleshoot. Thanks in advance for any ideas people might have.
More info:
- I'm using a virtualenv
- The application launches and runs without any errors
- PyCharm is popping up the "package requirements are not satisfied" message when I first open the project (and one of the requirements it's saying isn't satisfied is Django), but the requirements are definitely installed, and when I go to the settings screen for the project in PyCharm to install them, it shows them as installed.
I'm starting to think it might be an issue with how I have the project set up, either the directory structure or maybe the fact that I'm using multiple settings files.
As far as the directory structure goes, I have a top-level directory that is my git repo root. Within that I have requirements.txt. Then inside that directory (i.e. a directory at the same level as requirements.txt) I have the root of the Django project – here's the high-level layout:
foo-project
requirements.txt
foo
foo
settings.py
settings
base.py
local.py
production.py
staging.py
manage.py
This is the project layout proposed in Two Scoops of Django if you're familiar with that book.
As far as how I fired this up as a project in PyCharm, I did File -> Open Directory and pointed to the root of the git repo as opposed to the root of the Django app itself.
So my first question is, and this may be at the heart of the unresolved reference error, why is PyCharm insisting that I don't have my package requirements satisfied when I do? Would that cause the unresolved reference errors? Do I need to move my requirements.txt file elsewhere, or is there a way to point PyCharm directly to it?
My second question is if this is related to the fact that I'm using multiple settings files? Each of the environment-specific settings files imports everything from the base file (from .base import *). In the PyCharm Python interpreter settings for this project I added –settings=foo.settings.local in the Additional options box. And when I launch the app from PyCharm, it very clearly says "Django version 1.5.1, using settings 'foo.settings.local'" in the console.
Note that I have not run into this issue in projects with the requirements.txt file in the same directory as manage.py and in which I use a single settings.py file, but before giving up on what I think is a much better project structure I figured I better ask what might be going on here.
Happy to provide more information to help troubleshoot. Thanks in advance for any ideas people might have.
Please sign in to leave a comment.
You can check that your Python packacking tools recognize the installation of Django by running this unit test in PyCharm for your virtualenv (you should change REQUIRED_PACKAGE and REQUIREMENTS_FILE accordingly).
What references are unresolved for you?
The major reference that is showing as unresolved is Django.
I'll check the unit test and see what that yields – thanks for pointing me to that!
Unit test passes.
The new project created in this way works fine. So what I'll do is wipe out my virtualenv and start over on the other project and see if that resolves it.
I can just blow this away entirely and start over but thought I'd ask about why PyCharm doesn't seem to be seeing/reading requirements.txt before I do that.
With hyphens in the directory name for the virtualenv, even when I did get the "Package requirements ... are not satisfied" message (and whether or not that would ever show up was inconsistent), there was no "Install requirements" link. Only the "Ignore requirements" link showed up, and if clicked on the message itself and chose "fix all" nothing happened. No errors or anything, nothing happened.
When I kept the project the same but created a new virtualenv with no hyphens in the directory name and pointed to that, it behaved as I would expect – got the requirements not satisfied message, the "install requirements" link appeared, and I could successfully install the requirements. Also, with no hyphen in the directory name I could install the requirements via terminal and PyCharm would recognize them.
I realize that for Django projects there can't be hyphens in the project name, but is this maybe a PyCharm issue where it isn't handling the virtualenv properly due to the hyphen?
I'm going to run through all this one more time to make sure that's the reason, but it certainly seems to be the case based on what I've been banging on thus far.
Thanks so much for the help as I worked through this. All is well now.
Could you please file a bug in our issue tracker and describe your configuration in detail? A small sample project attached to the issue would be very welcome.