1

我目前正在尝试使带有 Python3.3 的 Django1.6b2 在我的服务器上工作。
我现在遇到了很多问题,以至于我无法列出它们(Flup、Threading、FastCGI),最后我快到了。这是我的 django.fcgi :

#!/home/benjamin/Python/3.3/bin/python3

import os, sys
import django
print("Django Version : {}".format(django.VERSION))
print("Python Version : {}".format(sys.version[:3]))

_PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, _PROJECT_DIR)
sys.path.insert(0, os.path.dirname(_PROJECT_DIR))

_PROJECT_NAME = _PROJECT_DIR.split('/')[-1]
os.environ['DJANGO_SETTINGS_MODULE'] = "%s.settings" % _PROJECT_NAME

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

这是我的回溯:

Traceback (most recent call last):
  File "website/public/django.fcgi", line 17, in <module>
    runfastcgi(method="threaded", daemonize="false")
  File "/home/benjamin/Python/3.3/lib/python3.3/site-packages/django/core/servers/fastcgi.py", line 143, in runfastcgi
    from django.core.servers.basehttp import get_internal_wsgi_application
  File "/home/benjamin/Python/3.3/lib/python3.3/site-packages/django/core/servers/basehttp.py", line 25, in <module>
    from django.core.wsgi import get_wsgi_application
  File "/home/benjamin/Python/3.3/lib/python3.3/site-packages/django/core/wsgi.py", line 1, in <module>
    from django.core.handlers.wsgi import WSGIHandler
  File "/home/benjamin/Python/3.3/lib/python3.3/site-packages/django/core/handlers/wsgi.py", line 9, in <module>
    from django import http
  File "/home/benjamin/Python/3.3/lib/python3.3/site-packages/django/http/__init__.py", line 4, in <module>
    from django.http.response import (HttpResponse, StreamingHttpResponse,
  File "/home/benjamin/Python/3.3/lib/python3.3/site-packages/django/http/response.py", line 17, in <module>
    from django.utils import six, timezone
  File "/home/benjamin/Python/3.3/lib/python3.3/site-packages/django/utils/timezone.py", line 11, in <module>
    import pytz
  File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
  File "/home/benjamin/modules/pytz-2013b-py2.6.egg/pytz/__init__.py", line 1103, in <module>
  File "/home/benjamin/modules/pytz-2013b-py2.6.egg/pytz/__init__.py", line 1103, in <listcomp>
  File "/home/benjamin/modules/pytz-2013b-py2.6.egg/pytz/__init__.py", line 107, in resource_exists
  File "/home/benjamin/modules/pytz-2013b-py2.6.egg/pytz/__init__.py", line 100, in open_resource
  File "/nfs/http7/benjamin/Python/distribute-0.7.3/pkg_resources.py", line 949, in resource_stream
    self, resource_name
  File "/nfs/http7/benjamin/Python/distribute-0.7.3/pkg_resources.py", line 1379, in get_resource_stream
    return StringIO(self.get_resource_string(manager, resource_name))
  File "/nfs/http7/benjamin/Python/distribute-0.7.3/pkg_resources.py", line 1956, in StringIO
    return StringIO(*args,**kw)
TypeError: initial_value must be str or None, not bytes

我该如何解决?似乎 Django 尝试导入一个我用 pip-3.3 (pytz-2013b-py2.6.egg) 找不到的模块,它是 2.6,为什么 pip 安装它?xD

有人可以帮助我吗?=)

4

1 回答 1

2

它看起来像以下位置的 python3 分发包中的错误 -

pkg_resources.py -> get_resource_string 这个方法返回字节并且 StringIO 期待字符串。我尝试使用 decode("ISO-8859-1") 方法对其进行解码,然后在 pytz 包中出现错误。

但是我得到了解决方法 -

在“site-packages/easy-install.pth”文件中将“./pytz-2013.7-py3.3.egg”更改为“./pytz”。

确保您在站点包目录中解压缩了 pytz 目录。

于 2013-11-01T12:58:17.127 回答