troubleshooting.txt 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ===============
  2. Troubleshooting
  3. ===============
  4. This page contains some advice about errors and problems commonly encountered
  5. during the development of Django applications.
  6. .. _troubleshooting-django-admin-py:
  7. Problems running django-admin.py
  8. ================================
  9. "command not found: django-admin.py"
  10. ------------------------------------
  11. :doc:`django-admin.py </ref/django-admin>` should be on your system path if you
  12. installed Django via ``python setup.py``. If it's not on your path, you can
  13. find it in ``site-packages/django/bin``, where ``site-packages`` is a directory
  14. within your Python installation. Consider symlinking to :doc:`django-admin.py
  15. </ref/django-admin>` from some place on your path, such as
  16. :file:`/usr/local/bin`.
  17. Script name may differ in distribution packages
  18. -----------------------------------------------
  19. If you installed Django using a Linux distribution's package manager
  20. (e.g. ``apt-get`` or ``yum``) ``django-admin.py`` may have been renamed to
  21. ``django-admin``; use that instead.
  22. Mac OS X permissions
  23. --------------------
  24. If you're using Mac OS X, you may see the message "permission denied" when
  25. you try to run ``django-admin.py``. This is because, on Unix-based systems like
  26. OS X, a file must be marked as "executable" before it can be run as a program.
  27. To do this, open Terminal.app and navigate (using the ``cd`` command) to the
  28. directory where :doc:`django-admin.py </ref/django-admin>` is installed, then
  29. run the command ``sudo chmod +x django-admin.py``.
  30. Running virtualenv on Windows
  31. -----------------------------
  32. If you used virtualenv_ to :ref:`install Django <installing-official-release>`
  33. on Windows, you may get an ``ImportError`` when you try to run
  34. ``django-admin.py``. This is because Windows does not run the
  35. Python interpreter from your virtual environment unless you invoke it
  36. directly. Instead, prefix all commands that use .py files with ``python`` and
  37. use the full path to the file, like so:
  38. ``python C:\pythonXY\Scripts\django-admin.py``.
  39. .. _virtualenv: http://www.virtualenv.org/
  40. Miscellaneous
  41. =============
  42. I'm getting a ``UnicodeDecodeError``. What am I doing wrong?
  43. ------------------------------------------------------------
  44. This class of errors happen when a bytestring containing non-ASCII sequences is
  45. transformed into a Unicode string and the specified encoding is incorrect. The
  46. output generally looks like this::
  47. UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position ?:
  48. ordinal not in range(128)
  49. The resolution mostly depends on the context, however here are two common
  50. pitfalls producing this error:
  51. * Your system locale may be a default ASCII locale, like the "C" locale on
  52. UNIX-like systems (can be checked by the ``locale`` command). If it's the
  53. case, please refer to your system documentation to learn how you can change
  54. this to a UTF-8 locale.
  55. * You created raw bytestrings, which is easy to do on Python 2::
  56. my_string = 'café'
  57. Either use the ``u''`` prefix or even better, add the
  58. ``from __future__ import unicode_literals`` line at the top of your file
  59. so that your code will be compatible with Python 3.2 which doesn't support
  60. the ``u''`` prefix.
  61. Related resources:
  62. * :doc:`Unicode in Django </ref/unicode>`
  63. * https://wiki.python.org/moin/UnicodeDecodeError