Django Error: Could not import settings 'interfaces.settings' - python

So, I'm fairly new to programming. I have relatively little background in django and don't understand much of its implementation. However I have read through django tutorials and have a basic understanding of the underlying structure.
So currently I am not actually modifying the django project being used by the server (lets call it /main), I think my coworker copied over the project to a new directory called /test. When I try to do anything with manage.py located in the /test directory by running
python2.4 manage.py runserver
I get an error saying
Django Error: Could not import settings 'interfaces.settings'
(Is it on sys.path? Does it have syntax errors?): No module named settings.
I've looked through the settings file and have tried changing main to test, but it hasn't changed anything.
Any guidance as to where I should look for a solution would be great.

Also?
It sounds like there is something hard-coded somewhere which expects the project to be in a directory called "interfaces", rather than "test". Try running manage.py shell --settings=settings, and see if that helps.
Actually, "also", you should not be editing code on the server, even if it's in a different directory to the production deployment. Install Django and the code on your local machine, and edit there.

The manage.py shell --settings=settings worked for me. I figured out from running django-admin.py runserver that settings could not be imported, because environment variable DJANGO_SETTINGS_MODULE was undefined.
Fix: export DJANGO_SETTINGS_MODULE=settings
I ran the command from the root of the project (same directory that had manage.py -- not sure if it matters). Then, running manage.py shell worked without the --settings=settings bit.
Cheers!

Try to undestand which versions of python you have installed.
Type python2 and press tab button in console.
It looks, that you are trying to run version of python, which has not django installed in libs.
Also try to run python2.4 in interactive mode from test folder and import settings.

Related

Django - Built project broken

So basically, I have a DJANGO project that can be executed and work well. And I don't know why (maybe I upgrade my django or sth) that this is no longer working.
First I try "python3 manage.py runserver" I get this from console:
So I try to collect the static file with "python3 manage.py collectstatic"
And I do have "ckeditor" in my static folder
And I'm sure that my project is work because it still online somewhere.
And notice 1 thing that in the project that my "manage.py" is not turning red. like this
I know its just UI behavior but it seems that the project is broken. Anyone has idea bout it?
It seems to me that you've got a python dependency problem. You've probably added django ckeditor in your INSTALLED_APPS settings, but it's not installed in your (virtual) env.
So have you installed django ckeditor using pip ? It's not related to the static folders or anything, they're not compile time errors. They are 404s.

Django: Nothing happens when I enter "python manage.py runserver" [duplicate]

I'm new to django and currently going through the main tutorial. Even though it was working earlier, when I do python manage.py runserver OR python manage.py -h OR with any other command, the shell doesn't output anything. Wondering what I'm doing wrong.
The problem is that the first line in manage.py breaks the file on windows.
The first line should look like this:
#!/usr/bin/env python
Removing it will fix the issue.
First, check if python is fully installed by typing "python" in a shell.
Then you should try python manage.py runserver inside your django project. If you don't have any django project, try creating one by typing django-admin.py startproject mysite. If nothing is displayed in your shell, you must have installed Django the wrong way.
Please refer to Django Documentation at https://docs.djangoproject.com/en/1.4/intro/install/
If you had your server running till one point and a certain action/change broke it, try going back to the previous state.
In my case there was an email trigger which would put the system in an invalid state if email doesn't go through. Doing git stash followed by selectively popping the stash and trying the runserver helps narrow down the problem to a particular file in your project.
Please try this.
Uninstall Python.
Go inside C drive and search Django. You will get many Django related files.
Delete every Django file. 😁 don't delete your Django files.
Install Python.
It's worked for me.
if you created a virtual environment then activate it. you can try this command(in virtual environment directory) if you're using windows os:
.\Scripts\activate
On Ubuntu works for my by running manage.py as script:
./manage.py runserver
Just stuck with the same problem. Found a solution that works, but tedious.
You need to know the location of the python.exe file in your computer. It is usually
C:/Users/USERNAME/AppData/Local/Programs/Python//python.exe
Modify as required and run the following in CMD,
C:/Users/USER1/AppData/Local/Programs/Python/Python38-32/python.exe
F:/mysite/manage.py runserver
Hope this works :)
if you are using Redis Server on Windows, check it out if Redis Server is running, I had same problem and realized my Redis Server was not running, I ran it and now my manage.py commands work fine.
The same happened with me also, but this issue is a minor one as it happens if you have multiple versions of Python on your system, you can select a specific Python version by running python3 or whichever version you want.
SO you should start from the beginning, uninstall Django first then,
create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path:
for e.g:
python3 -m venv tutorial-env
//This will create the tutorial-env directory if it doesn’t exist, and also create directories inside it
Once you’ve created a virtual environment, you may activate it.
On Windows, run:
tutorial-env\Scripts\activate.bat
On Unix or MacOS, run:
source tutorial-env/bin/activate
Now,
In the command prompt, ensure your virtual environment is active, and execute the following command:
...> py -m pip install Django
NOTE:
If django-admin only displays the help text no matter what arguments it is given, there is probably a problem with the file association in Windows. Check if there is more than one environment variable set for running Python scripts in PATH. This usually occurs when there is more than one Python version installed.
Another solution, if you can, is to upgrade Django
pip install django --upgrade
Oftentimes one will get other unrelated issues to solve that are linked with the upgrade but once all is fixed the server should run just fine.
If you can't upgrade Django, this problem also happens when the code was built using Python 2.x and you're locally using Python 3.x.
The quicker fix in that case is to uninstall Python 3.x from your machine and make sure Python 2.x was added to the path. I've seen some developers setting up alias in PowerShell to have more than one version in the environment too.
I think the problem is in manage.py file (50%), check it with an another file that is correct.

Django 1.4 Unknown command: 'runserver'

Something in my python path must have changed because now I cannot run the.
python app/manage.py runserver
The output I get is
Unknown command: 'runserver'
Type 'manage.py help' for usage.
I've looked at my environment's PYTHONPATH and PATH variables, but I can't figure out why its not running.
I've found the answer to my question.
If you've got an error in your settings, manage.py will swallow the exception and report as if the command does not exist.
This lead me down the path of incorrectly assuming my python path or venv environment was messed up.
If you want to diagnose this issue, run...
python app/manage.py help
... and it will show the exception. This, of course, was what was recommended by the django shell after it had told me that the command was not found.
This is clearly a bug in Django 1.4. It seems to me, an Exception should be reported regardless of what management command you run.
Looking through the manager.py code and django.core.management I can come up with some suggestions.
First, check if the file <some_path>/django/core/management/commands/runserver.py exists.
Second, run:
>>> import sys
>>> sys.path
If the aforementioned <some_path> is not in this list than you must set the PYTHONPATH variable.
Third, (and that's the longest of all shots) if you have changed the DEFAULT_PORT of runserver, try changing it back to 8000.
I agreed with OP. I met the same problem, and it turned out to be an error in settings.py:
In settings.py I use os.environ[something] and those environment variables are loaded in apache start script. If I run manage.py from the command line, it doesn't know what is os.environ[something] thus error occurs.
So for anyone here searching for solution, suggestion is to check circumstance difference between running django project and pure manage.py, maybe you'll find what's wrong.
I will add my answer to the same problem I had. This was unrelated from Django version, but in an old instance of my project I was providing my own Django copy and not installing from pip. Later I decided to use Pip installed Django.
When I pulled the changes on the server, my repo's copy of Django files were deleted but not the .pyc files. manage.py would still import the old .pyc files making the imports break half way and the error was the same "Unknown command: runserver".
Naturally, fully deleting the folder with the .pyc files fixed the problem.

Django is not accepting arguments in Windows

I have installed django on my windows vista computer and can add the django library to a python script, but cannot seem to ge teh following to work correctly from the command line:
django-admin.py startproject mysite
When I try to run this or the help command I always get the default message that shows all the commands as if I did not send it the second argument.
Any ideas on how to resolve this issue?
try
python django-admin.py startproject mysite
you may cd to the dir which the django-admin.py in
The biggest headache I've run into with developing on Windows is path issues. I use virtualenv and David Marble's port of virtualenvwrapper As such, I fully qualify the path to django-admin.py. Of course, the virtualenv's site-packages could get added to my PATH, but I find it just as easy to just paste in the path.
Try fully qualifying the path to django-admin.py and see if that gets you going.
If python variable environment is set you should try something like
python Path\to\django\installation\bin\django-admin.py startproject mysite
FYI, I figured out the issue based on another thread I found here:
Windows is not passing command line arguments to Python programs executed from the shell
The issue was about how the registry was handling my calls to admin.py and the fact that it was dropping the arguments I passed.
Hope this helps others who run into this issue.

Why is django giving error: no module named django.core?

I get the error in question when I attempt to create a project. I followed the instructions found at how to install python an django in windows vista.
Also make sure that you have permission to access all of django's files. I've seen these kinds of errors happen because of permissions issues before.
EDIT: I haven't tried it out, but there's a link on that page to Instant Django, which looks like a pretty easy to set up.
You can get around this problem by providing the full path to your django-admin.py file
python c:\python25\scripts\django-admin.py startproject mysite
Most likely you don't have Django on your Python path. To test, quickly fire up Python and run:
>>> import django
If that fails, it's just a matter of getting Django onto your Python path. Either you set the environment variable, or you move django into your python2x/Lib/site-packages directory. If it does work, try importing core. If that fails there, then something is probably wrong with your Django install.
From your command line (cmd) run "ftype Python.File" and make sure that your .py files are being executed by the correct version/installation of Python.
It's possible another application has surreptitiously changed this under the hood.

Categories

Resources