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.
Related
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'.
Just updated my Mac to El Capitan 10.11.
I am trying to run Django 1.6 with Celery 3.1 and I'm getting this error now:
Unhandled exception in thread started by <function wrapper at 0x10f861050>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/utils/autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 101, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name, True)
File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('%s.models' % app_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/debug_toolbar/models.py", line 9, in <module>
dt_settings.patch_all()
File "/Library/Python/2.7/site-packages/debug_toolbar/settings.py", line 215, in patch_all
patch_root_urlconf()
File "/Library/Python/2.7/site-packages/debug_toolbar/settings.py", line 203, in patch_root_urlconf
reverse('djdt:render_panel')
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 503, in reverse
app_list = resolver.app_dict[ns]
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 329, in app_dict
self._populate()
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 267, in _populate
for pattern in reversed(self.url_patterns):
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 365, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py", line 360, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/pedrotorres/Documents/work/projects/bparts/netpecasv2/urls.py", line 10, in <module>
url(r'', include('Common.urls')),
File "/Library/Python/2.7/site-packages/django/conf/urls/__init__.py", line 26, in include
urlconf_module = import_module(urlconf_module)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/pedrotorres/Documents/work/projects/bparts/Common/urls.py", line 3, in <module>
from APIMobile.views import request_product_info_by_qrcode
File "/Users/pedrotorres/Documents/work/projects/bparts/APIMobile/views.py", line 9, in <module>
from Common.views import resizeImage, token_generator, getWatermarkImage, filterProductsByBrandModelVersionYear, \
File "/Users/pedrotorres/Documents/work/projects/bparts/Common/views.py", line 34, in <module>
from Common.tasks import turn_off_demo_mode_new_workshop
File "/Users/pedrotorres/Documents/work/projects/bparts/Common/tasks.py", line 3, in <module>
from netpecasv2.celeryapp import app
File "/Users/pedrotorres/Documents/work/projects/bparts/netpecasv2/celeryapp.py", line 5, in <module>
from celery import Celery
File "/Library/Python/2.7/site-packages/celery/__init__.py", line 130, in <module>
from celery import five
File "/Library/Python/2.7/site-packages/celery/five.py", line 51, in <module>
from kombu.five import monotonic
File "/Library/Python/2.7/site-packages/kombu/five.py", line 52, in <module>
libSystem = ctypes.CDLL('libSystem.dylib')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: dlopen(libSystem.dylib, 6): image not found
Everything worked fine before.
Can't find a solution to fix this. I've seen this thread but doesn't work:
"OSError: dlopen(libSystem.dylib, 6): image not found" (OS X + macports + Celery 3.1.7)
I didn't have any DYLD_FALLBACK_LIBRARY_PATH before. I tried to:
export DYLD_FALLBACK_LIBRARY_PATH="/usr/lib":$DYLD_FALLBACK_LIBRARY_PATH
but Python can't find the Library despite it being located under "/usr/lib"
Anyone has had a problem like this?
I suspect (but can't confirm) the System Integrity Protection (SIP) of OSX El Capitan is preventing access to your /usr/lib folder.
It would be extreme and defeating the purpose of the security feature, but you could try disabling SIP by booting into the OS X Recovery partition, executing csrutil disable and rebooting...atleast until another option / work-around can be found.
ArsTechnica has a write-up here: http://arstechnica.com/apple/2015/09/os-x-10-11-el-capitan-the-ars-technica-review/9/
And a similar issue is described here: http://blog.honekamp.net/blog/2015/09/07/el-cap-and-my-printer/
More discussion on Hacker News here: https://news.ycombinator.com/item?id=10309576
pip install --upgrade billiard
pip install --upgrade celery
pip install --upgrade kombu
pip install --upgrade amqp
This should work.
I uninstall "billiard,celery,kombu,amqp" those four packages. Then reinstall the latest version from github solved this
I also ran into the same problem just after upgrading the OS to OS X El Captain. Disabling SIP does the trick, but if someone is not comfortable doing that updating five.py in few modules in site-packages will help. (I know it's not that nice, but it's OK as long as you know what you're doing)
Update the places that access the DLL to have absolute path in following modules
line 145 of site-packages/amqp/five.py
line 52 of site-packages/kombu/five.py
line 42 of site-packages/billiard/five.py
update to:
libSystem = ctypes.CDLL('libSystem.dylib') => libSystem = ctypes.CDLL('/usr/lib/libSystem.dylib')
hope this helps ;)
I ran into the same issue getting celery to work.
I did some quick tests and here's what I found, but can't quite pin it on a specific cause yet:
a. stock python with ctypes.CDLL("libSystem.dylib") results in the image not found error.
b. stock python with ctypes.CDLL("/usr/lib/libSystem.dylib") works
c. virtualenv python with ctypes.CDLL("libSystem.dylib") works
Reinstalling python solved the issue for me. Using brew you can just brew install python again. If it says that you need permission to write to /usr/local, try to change permissions by sudo chown -R $(whoami):admin /usr/local, and then install python.
I tried updating to the latest versions of these libraries from github, but it did not help. The simplest solution that I've found is to use virtualenv
virtualenv myenv
cd myenv
source bin/activate
pip install celery
To confirm it worked:
python -c "import celery"
This seems preferable to disabling a fundamental security feature of the OS, and virtualenv has its own (well documented) benefits.
You can delete the current celery version, and then download it from the http://pypi.python.org/pypi/celery/, build and install the sorce code.It is helpful for me, and I hope so do you.
In my case, the error is because Homebrew was not symlink to gettext properly. I've solved this using
brew unlink gettext && brew link --force gettext
copying from How to install h5py (needed for Keras) on MacOS with M1?
in case someone ended up here first like I was and wants to avoid disabling SIP. this seems to work for me:
brew install hdf5#1.10
export HDF5_DIR=/usr/local/Cellar/hdf5#1.10/1.10.7_1
pip install 'h5py==2.10.0' --force-reinstall --no-binary=h5py
1 . Install Homebrew as macOS Sur is missing the necessary ODBC package
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2 . Install missing ODBC package
brew install libiodbc
I have installed Django 1.6.5 with PIP and Python 2.7.8 from the website.
I ran django-admin.py startproject test123, switched to test123 directory, and ran the command python manage.py runserver, then i get this:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 50, in _setup
self._configure_logging()
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/conf/__init__.py", line 72, in _configure_logging
from django.utils.log import DEFAULT_LOGGING
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/utils/log.py", line 7, in <module>
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/views/debug.py", line 10, in <module>
from django.http import (HttpResponse, HttpResponseServerError,
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/http/__init__.py", line 2, in <module>
from django.http.request import (HttpRequest, QueryDict, UnreadablePostError,
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/http/request.py", line 11, in <module>
from django.core import signing
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/core/signing.py", line 45, in <module>
from django.utils.crypto import constant_time_compare, salted_hmac
File "/Library/Python/2.7/site-packages/Django-1.6.5-py2.7.egg/django/utils/crypto.py", line 6, in <module>
import hmac
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hmac.py", line 8, in <module>
from operator import _compare_digest as compare_digest
ImportError: cannot import name _compare_digest
Found out that operator is a standard python library. Why cant it not import it?
P.S. I did try it in the command line, I can import the operator module, but I get an error on this statement: from operator import _compare_digest as compare_digest
Followed this SO answer:
Uninstall python.org version of python2.7 in favor of default OS X python2.7
Then changed my .bash_profile Python path to /usr/lib/python for the default OSX python path.
Uninstalled Django and MySQL-Python:
sudo pip uninstall django
sudo pip uninstall MySQL-Python
And then again reinstalled everything, but with MySQL-Python being the first and second Django.
After these steps, everything is working.
I get this error with anaconda as my default python and django1.7 while trying to use startproject.
I deleted the venv and recreated it with
virtualenv -p /usr/bin/python2.7 venv
startproject was working again.
You most likely have another file named operator.py on your PYTHONPATH (probably in the current working directory), which shadows the standard library operator module..
Remove or rename the file.
For those not wanting to switch to Apple's python, simply deleting the virtualenv and rebuilding it worked fine for me.
Tip: Don't forget to pip freeze > requirements.txt first if you aren't already tracking your package requirements. That way you can pip install -r requirements.txt to get up and running again quickly.
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
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