I've created a completely empty PyDev project (NOT "PyDev Django", just "PyDev"), with this single file in it:
import unittest
class Test(unittest.TestCase):
def testName(self):
print "hello world"
And when I either right-click on the file and select "Run As"->"Python unit test", or press CTRL+F9 and click on "testName", I get this error:
Traceback (most recent call last):
File "C:\Program Files\Brainwy\LiClipse 1.2.0\plugins\org.python.pydev_3.8.0.201409251617\pysrc\runfiles.py", line 201, in <module>
main()
File "C:\Program Files\Brainwy\LiClipse 1.2.0\plugins\org.python.pydev_3.8.0.201409251617\pysrc\runfiles.py", line 26, in main
import pydev_runfiles
File "C:\Program Files\Brainwy\LiClipse 1.2.0\plugins\org.python.pydev_3.8.0.201409251617\pysrc\pydev_runfiles.py", line 5, in <module>
django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 20, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
If I put this in the file:
if __name__ == "__main__":
unittest.main()
and execute it using "Run As"->"Python Run", it works fine, but of course it's inconvenient in case there are many tests in the file.
How do I get PyDev to execute the unit tests without Django?
Solved by updating LiClipse from 1.2.0 to 1.4.0 :)
Related
I'm relatively new to Django and programming, so I have no idea what caused this error or how to fix it. I asked another question related to the same error but got no responses so here's a simpler version.
When I run Django-admin check (along with various other commands not including run server) I get the following error.
django.core.exceptions.ImproperlyConfigured: Requested setting LANGUAGE_CODE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I have spent hours googling and nothing I find works (I either get this error or a module not found error). What can I do?
here's the full traceback:
Traceback (most recent call last):
File "/Users/linnea/opt/miniconda3/bin/django-admin", line 8, in <module>
sys.exit(execute_from_command_line())
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/commands/check.py", line 69, in handle
databases=options['databases'],
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/base.py", line 396, in check
databases=databases,
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/checks/translation.py", line 60, in check_language_settings_consistent
get_supported_language_variant(settings.LANGUAGE_CODE)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/conf/__init__.py", line 83, in __getattr__
self._setup(name)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/conf/__init__.py", line 68, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting LANGUAGE_CODE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Edit: I get the module not found error (no module named ) when I set the Django settings module
The problem is that Django cannot find your settings.py file to run the app. You need to set the environment variable DJANGO_SETTINGS_MODULE to point to you settings.py or if you're using an IDE just add it to your project config.
I'm coming into an inherited Django project, so I can't say how it was originally set up. However, pip freeze tells me that django-cms is installed in the virtualenv:
(demo)$ pip freeze
...
django-cms==3.3.0
...
So why when I do anything with, manage.py, do I get an error saying it's not available?
(demo)$
./manage.py shell
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 328, in execute
django.setup()
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/iscape/sites/demo/local/lib/python2.7/site-packages/django/apps/config.py", line 112, in create
mod = import_module(mod_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named cms
I can also confirm that VIRTUAL_ENV has the correct value in the "activate" script. It's like pip knows what's installed, but Django doesn't.
This is Django1.8, btw, though I don't know how much of a factor that is.
Any ideas? I'm getting nothing out of the stack trace and don't know where else to look.
At some point my project has stoped running IPython shell. ./manage.py shell --plain however still works fine. Unfortunately i don't remember exactly at what moment that happened but it might be due to some packages conflicting with each other. I am running my project in a virtualenv, other virtualenv's with common package set-up work just fine.
Here is the error traceback:
$ ./manage.py shell
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/django/core/management/commands/shell.py", line 81, in handle_noargs
self.run_shell(shell=interface)
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/django/core/management/commands/shell.py", line 61, in run_shell
return getattr(self, shell)()
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/django/core/management/commands/shell.py", line 44, in ipython
ip()
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/django/core/management/commands/shell.py", line 37, in _ipython
from IPython import start_ipython
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/IPython/__init__.py", line 47, in <module>
from .terminal.embed import embed
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/IPython/terminal/embed.py", line 35, in <module>
from IPython.terminal.ipapp import load_default_config
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/IPython/terminal/ipapp.py", line 47, in <module>
from IPython.core.magics import ScriptMagics
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/IPython/core/magics/__init__.py", line 22, in <module>
from .execution import ExecutionMagics
File "/home/pk/.virtualenvs/eissvedvl/lib/python3.4/site-packages/IPython/core/magics/execution.py", line 27, in <module>
import cProfile as profile
File "/usr/lib/python3.4/cProfile.py", line 22, in <module>
run.__doc__ = _pyprofile.run.__doc__
AttributeError: 'module' object has no attribute 'run'
Here is my requirements.txt:
Django==1.6.5
South==1.0
Werkzeug==0.9.6
django-admin-bootstrapped==1.6.6
django-ajax-selects==1.3.5
django-allauth==0.18.0
django-braces==1.4.0
django-crispy-forms==1.4.0
django-extensions==1.3.11
ipython==2.3.0
oauthlib==0.6.3
psycopg2==2.5.3
requests==2.4.3
requests-oauthlib==0.4.2
six==1.7.3
I would appreciate any help to solve the issue. I have already tried to use different versions of IPython but the shell still wouldn't start.
This maybe in your code package name profile. Refactor your code
I recently upgraded my Ubuntu to 14.04, and consulted this question to solve my erros, ImportError: No module named _io in ubuntu 14.04. That was solved perfectly.
I also checked out this question as it's similar to mine, Consistently getting ImportError: Could not import settings 'myapp.settings' error, but could not use the same solution.
I do not use manage.py in my project and I have done numerous exports of the PYTHON_PATH to no end of my issues. Here is my traceback;
Traceback (most recent call last):
File "/home/thabang/.virtualenvs/lottostar/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'lottostar.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named lottostar.settings
I found the problem:
The was an issue with the egg files during the virtualenv reinstall. Though the programs were there, they couldn't be found. I just performed another install of the requirements to refresh the egg info.
I'd like to put a flickr feed on my homepage using django-syncr; I followed the instructions on the homepage (http://code.google.com/p/django-syncr/), and the installation process was pretty smooth. Steps 1-3 work just fine, but Step 4 is where I run into problems.
When I try to run the commands shown:
from syncr.app.flickr import FlickrSyncr
I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django_syncr-0.50-py2.7.egg/sync/app/flickr.py", line 11, in <module>
from syncr.flickr.models import *
File "/usr/local/lib/python2.7/dist-packages/django_syncr-0.50-py2.7.egg/syncr/flickr/models.py", line 1, in <module>
from django.db import models
File "/usr/lib/python2.7/dist-packages/django/db/__init__.py", line 14, in <module>
if not settings.DATABASES:
File "/usr/lib/python2.7/dist-packages/django/utils/functional.py", line 276, in __getattr__self._setup()
File "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
And I'm not really sure what to do. These files are run in my django project folder, but including the settings file (via import settings) doesn't seem to fix this. What files should be included in order to import the right variables?
thanks!