我在django中创建了一个项目.我使用pyinstaller为它创建了安装程序.如果我使用python manage.py runserver运行项目,那么项目运行正常没有任何错误,但我无法通过安装程序运行它.运行安装程序时出错.
C:\The_Incredibles\Pyinstaller Story\test_proj>.\dist\demo\demo.exe runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
at 0x03A15978>
Traceback (most recent call last):
File "site-packages\django-1.10.4-py3.5.egg\django\utils\autoreload.py", line
226, in wrapper
File "site-packages\django-1.10.4-py3.5.egg\django\core\management\commands\ru
nserver.py", line 113, in inner_run
File "site-packages\django-1.10.4-py3.5.egg\django\utils\autoreload.py", line
249, in raise_last_exception
File "site-packages\django-1.10.4-py3.5.egg\django\utils\six.py", line 685, in
reraise
File "site-packages\django-1.10.4-py3.5.egg\django\utils\autoreload.py", line
226, in wrapper
File "site-packages\django-1.10.4-py3.5.egg\django\__init__.py", line 27, in s
etup
File "site-packages\django-1.10.4-py3.5.egg\django\apps\registry.py", line 85,
in populate
File "site-packages\django-1.10.4-py3.5.egg\django\apps\config.py", line 116,
in create
File "importlib\__init__.py", line 126, in import_module
File …Run Code Online (Sandbox Code Playgroud) 我尝试使用 pyinstaller 将 Django 项目转换为 exe,但我无法转换它。
我的 Django 项目叫做 mysite
这是我执行的命令:
pyinstaller --name=mysite mysite/manage.py
执行上述命令后build,dist和mysite.spec被创造,但dist不包含mysite.exe
root@ayachp-ind:~/mysite_demo# pyinstaller --name=mysite mysite/manage.py
24 INFO: PyInstaller: 3.2
24 INFO: Python: 2.7.6
24 INFO: Platform: Linux-3.5.0-39-generic-x86_64-with-Ubuntu-14.04-trusty
25 INFO: wrote /root/mysite_demo/mysite.spec
30 INFO: UPX is not available.
31 INFO: Extending PYTHONPATH with paths
['/root/mysite_demo/mysite', '/root/mysite_demo']
31 INFO: checking Analysis
31 INFO: Building Analysis because out00-Analysis.toc is non existent
31 INFO: Initializing module dependency graph...
33 INFO: Initializing …Run Code Online (Sandbox Code Playgroud) 我是 django 的新手。我已经在 django 中创建了项目。运行它时我收到以下错误。此错误来自模板。
django.template.exceptions.TemplateSyntaxError: 'static' is not a registered tag library. Must be one of:
Run Code Online (Sandbox Code Playgroud)
这是我的index.html。我按照 djnago 文档中的步骤操作
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}" />
{% if latest_question_list %}
<ul>
{% for question in latest_question_list %}
<li><a href ="{% url 'polls:detail' question.id %}">{{question.question_text}}</a></li>
{% endfor %}
</ul>
{% else %}
<p> No polls are available</p>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
以下是setting.py。将静态更新为静态文件后仍然面临同样的问题。
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.10.2.
For …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 python 脚本中读取一个日志文件。我的程序在 Linux 中运行良好,但在 windows 中出现错误。在特定行号读取某些行后,出现以下错误
File "C:\Python\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 311: char
acter maps to <undefined>
Run Code Online (Sandbox Code Playgroud)
以下是我用来读取文件的代码
with open(log_file, 'r') as log_file_fh:
for line in log_file_fh:
print(line)
Run Code Online (Sandbox Code Playgroud)
我试图通过使用不同的编码模式来修复它,如 ascii、utf8、utf-8、ISO-8859-1、cp1252、cp850。但仍然面临同样的问题。有什么办法可以解决这个问题。