django run server error with mysql - python

After I solve the issue with "image not found" when I run python manage.py syncdb by adding "export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/" into .bash_profile.
The problem comes with python manage.py runserver
Does anyone know how to solve OSError(Errno 20)?
System check identified no issues (0 silenced).
October 07, 2014 - 18:19:56
Django version 1.8, using settings 'dbtest.settings'
Starting development server at http:/127.0.0.1:8000/
Quit the server with CONTROL-C.
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.8-py2.7.egg/django/core/management/__init__.py", line 330, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/__init__.py", line 322, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/base.py", line 363, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/base.py", line 412, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/commands/runserver.py", line 80, in handle
self.run(**options)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/commands/runserver.py", line 89, in run
autoreload.main(self.inner_run, None, options)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/utils/autoreload.py", line 320, in main
reloader(wrapped_main_func, args, kwargs)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/utils/autoreload.py", line 286, in python_reloader
reloader_thread()
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/utils/autoreload.py", line 262, in reloader_thread
change = fn()
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/utils/autoreload.py", line 200, in code_changed
stat = os.stat(filename)
OSError: [Errno 20] Not a directory: '/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.9-intel.egg/MySQLdb/converters.py'

I just realize that I install both mysql-python and mysql-connector-python packages.
By changing the database 'ENGINE' setting from 'django.db.backends.mysql' to 'mysql.connector.django', the issue is solved.
Lesson learned here: I should probably use virtualenv to try different python package.

Related

Django fails to import any package : AttributeError: __name__

For some reasons, I had to reinstall Python on my desktop. Since then, my django applications are not working. I can create one, but as soon as I import a package anywhere in the application, I can't run python manage.py runserver
I can run another python script, I can start Jupyter Notebooks (and import the exact same packages in them). I also tried to create new projects with the "new" python installed, as soon as I add import pandas (or any other packages except django), I have the error.
The error message is quite long :
Watching for file changes with StatReloader
Performing system checks...
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 585, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 570, in start_django
reloader.run(django_main_thread)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 288, in run
self.run_loop()
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 294, in run_loop
next(ticker)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 334, in tick
for filepath, mtime in self.snapshot_files():
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 350, in snapshot_files
for file in self.watched_files():
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 249, in watched_files
yield from iter_all_python_module_files()
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 116, in iter_modules_and_files
if module.__name__ == '__main__':
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\py\_
apipkg.py", line 171, in __getattribute__
return getattr(getmod(), name)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\py\_
error.py", line 44, in __getattr__
raise AttributeError(name)
AttributeError: __name__
Got this annoying error after aborting an IDE-refactoring.
I suggest the following to reproduce the problem:
Revert git changes.
Make sure there are no cyclic imports in your code.
Reinstall virtual environment.
Unfortunately the error was still there in my case. So I knew the problem must be with python. And indeed:
Reinstalling python 3.7 solved the problem.
Did you pip install django?
I think when you reinstalled Python you didn't installed packaged like Django
Uninstall the current Django package and install Django 2.1.5
Use this command on windows:
pip install --user django==2.1.5

CircleCI test failing due to an apparent merge conflict in /usr/local/lib/python3.6

I'm trying to push a commit, but our CircleCI yields the following puzzling error message:
#!/bin/bash -eo pipefail
cd lucy-web
source venv/bin/activate
python manage.py compilescss --verbosity 0
python manage.py collectstatic --clear --no-input --verbosity 0
python manage.py test
Traceback (most recent call last):
File "manage.py", line 29, in <module>
execute_from_command_line(sys.argv)
File "/root/lucy/lucy_web/lucy-web/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/root/lucy/lucy_web/lucy-web/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/root/lucy/lucy_web/lucy-web/venv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/root/lucy/lucy_web/lucy-web/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/root/lucy/lucy_web/lucy-web/venv/lib/python3.6/site-packages/sass_processor/management/commands/compilescss.py", line 153, in handle
self.parse_source(py_source)
File "/root/lucy/lucy_web/lucy-web/venv/lib/python3.6/site-packages/sass_processor/management/commands/compilescss.py", line 199, in parse_source
tree = ast.parse(open(filename, 'rb').read())
File "/usr/local/lib/python3.6/ast.py", line 35, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
File "<unknown>", line 26
<<<<<<< HEAD
^
SyntaxError: invalid syntax
Exited with code 1
It seems like there are git merge conflicts in Python's ast.py. How might this have come about, and how can I fix it?

AttributeError: 'FlashPolicyServer' object has no attribute 'kill'

I get the following error as soon as I run django app along with the django-socketio app using python manage.py runserver_socketio
SocketIOServer running on 127.0.0.1:8001
KeyboardInterrupt
Thu Jul 6 22:04:52 2017
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/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django_socketio-0.3.9-py2.7.egg/django_socketio/management/commands/runserver_socketio.py", line 65, in handle
server.kill()
File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 43, in kill
self.policy_server.kill()
AttributeError: 'FlashPolicyServer' object has no attribute 'kill'
Am I missing something ?
Inspired by this issue, I tried downgrading gevent-socketio and gevent and it worked.
pip uninstall gevent-socketio gevent
pip install gevent-socketio==0.2.1 gevent==0.13.6

django-jenkins - AttributeError: 'Coverage' object has no attribute '_harvest_data'

I have installed django-jenkins in following environment
coverage (4.0.1)
Django (1.8)
pep8 (1.6.2)
django-jenkins (0.17.0)
pyflakes (1.0.0)
and I when I try this
python manage.py jenkins --enable-coverage
I get this error
Destroying test database for alias 'default'...
Storing coverage info...
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/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django_jenkins/management/commands/jenkins.py", line 161, in handle
coverage.save(tested_locations, options)
File "/usr/local/lib/python2.7/dist-packages/django_jenkins/tasks/with_coverage.py", line 33, in save
self.coverage.stop()
AttributeError: 'Coverage' object has no attribute '_harvest_data'
Any ideas ? I followed this manual exactly.
I found out the django-jenkins uses Coverage and in newest version of coverage the method _harvest_data has changed to get_data but in the final official release of django-jenkins it has not been applied so I switched to their latest git version and it solved.

django manage.py migrate raises AttributeError

When I try to migrate my db, I'm getting this error:
Running migrations for easy_thumbnails:
- Nothing to migrate.
- Loading initial data for easy_thumbnails.
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/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/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/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
ignore_ghosts = ignore_ghosts,
File "/Library/Python/2.7/site-packages/south/migration/__init__.py", line 233, in migrate_app
migrator.load_initial_data(target, db=database)
File "/Library/Python/2.7/site-packages/south/migration/migrators.py", line 222, in load_initial_data
self.post_1_6(target, db)
File "/Library/Python/2.7/site-packages/south/migration/migrators.py", line 240, in post_1_6
old_cache = django.db.models.loading.cache
AttributeError: 'module' object has no attribute 'loading'
Apps versions are:
Django 1.6.2
Easy thumbnails 1.4
Mptt 0.5.5
Pymorphy 0.5.6
Python 2.7.5
Pytils 0.3dev
South 0.8.4
Suit 0.2.5
It's looks like not easy_thumbnails problem, because when I try to migrate my django-allauth it raises the same error.
Please, help me!
It seems like your django package was broken. Check that there is python2.7/site-packages/django/db/models/loading.py file in your environment. Or just reinstall django package.
pip install -U --force-reinstall django

Categories