django project not working in virtualenv - python

I recently installed a virtualenv and cloned an existing django project into it. When I run python manage.py runserver I'm getting the following error:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 8, in <module>
from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 26, in <module>
from django.views import static
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/views/static.py", line 95, in <module>
template_translatable = ugettext_noop(u"Index of %(directory)s")
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
return _trans.gettext_noop(message)
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 48, in __getattr__
if settings.USE_I18N:
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/Users/user/eb-virt/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'application-name.settings' (Is it on sys.path?): No module named application-name.settings
when I try doing application-name/application python manage.py runserver, I get the following error:
python: can't open file 'manage.py': [Errno 2] No such file or directory
here is the application directory
application-name/
manage.py
application/
__init__.py
urls.py
wsgi.py
settings.py

First, rename your application-name to application_name. Dashes and Python source is just inviting problems, best not wake the dragons.
Let's assume you've put it in ~/work/application_name, i.e. outside your virtualenv.
If you didn't create the virtualenv with virtualenvwrapper and it doesn't have a setup.py file, then delete it (and install virtualenvwrapper).
Create your virtualenv with virtualenvwrapper:
mkvirtualenv -a ~/work/application_name -r ~/work/application_name/requirements.txt eb_virt
-a add an existing directory as a project dir (puts it on the python path for this virtualenv). -r runs pip install -r on the argument (I'm assuming application_name/requirements.txt exists).
Instead of using the -a option (and assuming application_name/setup.py exists), you can install your package in development mode :
cd ~/work
pip install -e application_name
Either of these make ~/work/application_name part of the module search path when Python is running. Your settings file path must start relative to a directory on Python's module search path.
The DJANGO_SETTINGS_MODULE environment variable, should therefore be set to 'application.settings'.

Related

Django/Python error. "ImportError: Import by filename is not supported."

I wanted to install Django and have troubles with the import error.
I read this topic, but the answer didn't help here. Nothing happend after I changed the env variables to the module path.
C:\Users\M>django-admin.py
Traceback (most recent call last):
File "C:\Python27\Scripts\django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 350, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 55, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: Import by filename is not supported.
DJANGO_SETTINGS_MODULE shouldn't be system path to settings file (or directory). It should be an python path to your settings file. So first, make sure that your project is in PYTHONPATH or you are inside project directory, then set correct DJANGO_SETTINGS_MODULE and after that, run your django-admin command.
You can also clean DJANGO_SETTINGS_MODULE variable if command that you're trying to issue is not related with existing django project.
I was facing the same issue in windows. Then later I realised that the problem is with the version of Django installed. I am using python 2.7, and it seems that the import by filename is not supported by it. I believe if you use python 3 , there wont be any problem.
So , I installed django 1.6.5 and the solved the problem.
pip install django==1.6.5

Importing existing project from PIL to Pillow

I've got a django (1.5.1) project. This project was built with PIL. Nowadays pip use only Pillow.
I ran my virtualenv, cd to project folder, installed all requirements (PIL is changed to Pillow) and stacked with problem.
>>python manage.py syncdb
No local settings
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/watashi/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/home/watashi/venv/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/watashi/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/watashi/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/watashi/venv/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/watashi/venv/lib/python2.7/site-packages/south/management/commands/__init__.py", line 10, in <module>
import django.template.loaders.app_directories
File "/home/watashi/venv/lib/python2.7/site-packages/django/template/loaders/app_directories.py", line 25, in <module>
raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
django.core.exceptions.ImproperlyConfigured: ImportError utils: No module named Image
To solve this problem I also tried following by this tutorial, but it didn't help. What wrong with it? How to understand that problem?
Other information:
manage.py script
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
The issue can be fixed by using the following command
pip install --upgrade setuptools .

Django ImportError: Could not import settings

I am getting following error. Before git pull and merge, everything was working fine. I checked the history to find removal of any files etc.
I have checked here. I have checked other ans on stackoverflow but, it didn't solve the problem.
I have checked sys.path. Project directory path is present in sys.path.
Someone mentioned to verify __init__.py file in myapp folder. It is present.
Bootstrap3 package is installed in system.
I ran python setup.py develop again.
Not sure how to debug this?
$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/core/management/__init__.py", line 263, in fetch_command
app_name = get_commands()[subcommand]
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/core/management/__init__.py", line 109, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/conf/__init__.py", line 48, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/conf/__init__.py", line 134, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'myapp.settings' (Is it on sys.path?): No module named bootstrap3
You are using bootstrap3 and its might be not installed or not in PYTHONPATH.
Original error is No module named bootstrap3, please check for bootstrap3 module.
You have to install requirements.txt and it will be ok !
run this command in your shell:
pip install -r requirements.txt

Django Local Installation syncdb ImproperlyConfigured

I have been struggling to get a local django installation set up on a mac osx10.6.8. Running syncdb fails to recognize the apps that I have installed.
admins-macbook:myproject Admin$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/Admin/myapp/lib/python2.7/site-packages/south/management/commands/__init__.py", line 10, in <module>
import django.template.loaders.app_directories
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/template/loaders/app_directories.py", line 23, in <module>
raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
django.core.exceptions.ImproperlyConfigured: ImportError haystack: cannot import name openProc
I have installed all the apps in the requirements.txt and they exist in the
lib/python2.7/site-packages/
directory. It is on my pythonpath:
admins-macbook:myproject Admin$ echo $PATH
/Users/Admin/myapp/lib/python2.7/site-packages:(... etc.)
How can I properly run syncdb? Thanks for your ideas!
you may installed pip install haystack which is wrong.
you need to install dyango haystack by pip install django-haystack
please refer this SO question

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module:

I am following the django tutorial, Many have asked the question but I think my situation is bit unique because after installing python-mysql I still get this error when I try to do python manage.py syncdb,
I am in a virtualenv since I use macports to manage my python installation I created my virtualenv
virtualenv code/vdjango --no-site-packages --python=/opt/local/bin/python
prior to this using macports I install django py27-django, but after creating my virtualenv I thought its better that I install django on to virtualenv so I used pip install django==1.5
According to django tutorial I edited my settings.py file and then execute the python manage.py syncdb and I end up with following error:
[~/code/vdjango/newsite]$python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/sql.py", line 9, in <module>
from django.db import models
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/utils.py", line 27, in load_backend
return import_module('.base', backend_name)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/mac-pro/code/vdjango/lib/python2.7/site-packages/_mysql.so
Reason: image not found
To confirm that I have install python-mysql package I ran the pip install again,
(vdjango)mac-pro#localhost:[~/code/vdjango/newsite]$pip install python-mysqldb
Downloading/unpacking python-mysqldb
Could not find any downloads that satisfy the requirement python-mysqldb
No distributions at all found for python-mysqldb
Storing complete log in /Users/mac-pro/.pip/pip.log
So whats happening here? Looks like I have everything that I need to go further with the tutorial but some how python/django is complaining about not having mysqldb.
My libmysqlclient.18.dylib was located in /usr/local/mysql/lib/ but my system was looking for it in /usr/lib/. I ended up creating a symbolic link of libmysqlclient.18.dylib in /usr/lib which fixed the problem.
1.) Make sure that libmysqlclient.18.dylib exists in /usr/local/mysql/lib/.
Open your shell.
sudo -s
ls /usr/local/mysql/lib/ | grep libmysqlclient.18.dylib
You should see the file:
libmysqlclient.18.dylib
If not, search your system for the location of the file:
find / -name libmysqlclient.18.dylib
2.) Create a symbolic link of libmysqlclient.18.dylib in /usr/lib
Enter the following command in your shell:
ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
If your libmysqlclient.18.dylib file wasn't located in /usr/local/mysql/lib replace the first path with the proper path to libmysqlclient.18.dylib.
Hopefully that helps.

Categories