DjangoPython管理.py找不到提供异常数据文件的runserver,数据文件生成失败

2024-09-24 06:20:42 发布

您现在位置:Python中文网/ 问答频道 /正文

在升级了我的一个包(django注册)之后,我在尝试运行python manage.py runserver时收到了这个错误

输出如下所示。在

我以为

python3.5/site-packages/confusable_homoglyphs/categories.py

可能丢失了,我重新安装了包confusable_homoglyphs,但没有用。它引发了相同的错误

在那之后

在我的项目文件夹中创建了一个文件名=3.0.0.txt,它写在下面

Requirement already satisfied: confusable_homoglyphs in ./myvenv/lib/python3.5/site-packages

我试图删除包并添加该包(甚至在虚拟环境之外的n内)。但它抛出了与下面相同的错误。在

(myvenv) shubhendu@shubhendu-HP-Pavilion-g6-Notebook-PC:/home/foodballbear$ python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f320538d400>
Traceback (most recent call last):
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/categories.py", line 141, in <module>
    categories_data = load('categories.json')
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/utils.py", line 33, in load
    with open('{}/{}'.format(os.getcwd(), filename), 'r') as file:
FileNotFoundError: [Errno 2] No such file or directory: '/home/foodballbear/categories.json'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/categories.py", line 144, in <module>
    if generate():
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/categories.py", line 111, in generate
    file = get(url)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/utils.py", line 24, in get
    return urlopen(url).read().decode('utf-8').split('\n')
  File "/usr/lib/python3.5/http/client.py", line 461, in read
    s = self._safe_read(self.length)
  File "/usr/lib/python3.5/http/client.py", line 607, in _safe_read
    chunk = self.fp.read(min(amt, MAXAMOUNT))
  File "/usr/lib/python3.5/socket.py", line 575, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/utils/autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/foodballbear/myfoodsite/urls.py", line 27, in <module>
    url(r'^accounts/', include('registration.backends.simple.urls')),
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/django/conf/urls/__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/backends/simple/urls.py", line 10, in <module>
    from . import views
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/backends/simple/views.py", line 10, in <module>
    from registration.views import RegistrationView as BaseRegistrationView
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/views.py", line 12, in <module>
    from registration.forms import RegistrationForm
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/forms.py", line 19, in <module>
    from . import validators
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/registration/validators.py", line 10, in <module>
    from confusable_homoglyphs import confusables
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/confusables.py", line 7, in <module>
    from .categories import unique_aliases, alias
  File "/home/foodballbear/myvenv/lib/python3.5/site-packages/confusable_homoglyphs/categories.py", line 147, in <module>
    raise Exception('Datafile not found, datafile generation failed!')
Exception: Datafile not found, datafile generation failed!

Tags: djangoinpyimporthomelibpackagesline
2条回答

您正试图访问categories.json在django中无法直接访问该文件。因此发生了异常。在

使用以下解决方案访问categories.json

from project_name.settings import BASE_DIR
import os

file_path = os.path.join(BASE_DIR, 'categories.json')
categories_data = load(file_path)

BASE_DIR为您提供项目目录路径,然后您希望使用os.path.join()加入文件路径

希望这对你有帮助

这个问题以前也有人提过

https://github.com/vhf/confusable_homoglyphs/issues/7

我现在可以通过管理.py,包似乎有问题

confusable_homoglyphs

每次加载时它都会下载文件。当依赖项经常被下载时,它会导致

ConnectionResetError: [Errno 104] Connection reset by peer

多亏了comment中提供的链接,该修补程序已被应用并将与confusable_homoglyphs>=3.0.0.配合使用

运行带有选项no site packages的virtualenv将不包括全局安装的包。它可能有助于保持包列表的整洁,以防以后需要访问它

为了保持环境的一致性,我“冻结”环境包的当前状态

$ pip freeze > requirements.txt

这是我的要求.txt在

^{pr2}$

这是我的要求.txt在我加上`

confusable_homoglyphs>=3.0.0

`所需版本

Django==1.11.1
django-dajax==0.9.2
django-dajaxice==0.7
django-filter==1.1.0
django-redis==4.8.0
djangorestframework==3.6.3
pkg-resources==0.0.0
psycopg2==2.7.3.2
pytz==2017.2
redis==2.10.6
confusable_homoglyphs>=3.0.0

然后我运行pip install -r requirements.txt

(myvenv) shubhendu@shubhendu-HP-Pavilion-g6-Notebook-PC:/home/foodballbear  :  pip install -r requirements.txt 
Obtaining bootstrap from git+git://github.com/earle/django-bootstrap.git@97eb50b3f4932798e7fa8ad4b42f0534d521826d#egg=bootstrap (from -r requirements.txt (line 1))
  Skipping because already up-to-date.
Requirement already satisfied: Django==1.11.1 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 2))
Requirement already satisfied: django-dajax==0.9.2 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 3))
Requirement already satisfied: django-dajaxice==0.7 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 4))
Requirement already satisfied: django-filter==1.1.0 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 5))
Requirement already satisfied: django-redis==4.8.0 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 6))
Requirement already satisfied: djangorestframework==3.6.3 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 7))
Requirement already satisfied: pkg-resources==0.0.0 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 8))
Requirement already satisfied: psycopg2==2.7.3.2 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 9))
Requirement already satisfied: pytz==2017.2 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 10))
Requirement already satisfied: redis==2.10.6 in ./myvenv/lib/python3.5/site-packages (from -r requirements.txt (line 11))
Collecting confusable_homoglyphs>=3.0.0 (from -r requirements.txt (line 12))
  Downloading confusable_homoglyphs-3.0.0-py2.py3-none-any.whl (173kB)
    100% |████████████████████████████████| 174kB 828kB/s 
Installing collected packages: bootstrap, confusable-homoglyphs
  Found existing installation: bootstrap 0.1.0
    Uninstalling bootstrap-0.1.0:
      Successfully uninstalled bootstrap-0.1.0
  Running setup.py develop for bootstrap
  Found existing installation: confusable-homoglyphs 2.0.2
    Uninstalling confusable-homoglyphs-2.0.2:
      Successfully uninstalled confusable-homoglyphs-2.0.2
Successfully installed bootstrap confusable-homoglyphs-3.0.0

在那之后,我的python manage.py runserver没有抛出任何错误

(myvenv) shubhendu@shubhendu-HP-Pavilion-g6-Notebook-PC:/home/foodballbear$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
December 12, 2017 - 06:08:24
Django version 1.11.1, using settings 'myfoodsite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

相关问题 更多 >