0

我正在尝试在我的 windows 10 64 位 pc 上设置一个新项目

这样做时,python manage.py makemigrations我不断收到ModuleNotFoundError: No module named 'qrcode.settings'

我已经成功安装了所有依赖项,在 venv 中运行了 cmd。

我寻找这个特定的问题,但找不到解决方案。我正在使用 Python 3.9。

依赖项是(点冻结)

asgiref==3.3.1
certifi==2020.4.5.1
cffi==1.14.3
chardet==3.0.4
colorama==0.4.4
cryptography==3.2.1
Django==3.1.3
djangorestframework==3.12.2
djangorestframework-jwt==1.11.0
idna==2.10
install==1.3.4
mysql-connector-python==8.0.22
mysqlclient @ file:///C:/Users/zubai/Downloads/mysqlclient-1.4.6-cp39- 
cp39-win32.whl
paypalrestsdk==1.13.1
Pillow==8.0.1
protobuf==3.14.0
pycparser==2.20
PyJWT==1.7.1
PyMySQL==0.10.1
pyOpenSSL==19.1.0
PyPDF2==1.26.0
PyQRCode==1.2.1
pytz==2020.4
qrcode==6.1
requests==2.25.0
six==1.15.0
sqlparse==0.4.1
urllib3==1.26.2

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'authe',
'user',
'qr',
'country',
'region',
'user_country',
'subscription',
'user_subscription',
'transaction',
'qradmin',
'corsheaders',
'django_crontab',
'paypal',

]

错误如下

    Traceback (most recent call last):
  File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\core\management\base.py", line 368, in execute
    self.check()
  File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\core\management\base.py", line 392, in check
    all_issues = checks.run_checks(
  File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\core\checks\templates.py", line 22, in check_setting_app_dirs_loaders
    for conf in settings.TEMPLATES
  File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\conf\__init__.py", line 83, in __getattr__
    self._setup(name)
  File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\conf\__init__.py", line 70, in _setup
    self._wrapped = Settings(settings_module)
  File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\conf\__init__.py", line 177, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "C:\Program Files\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'qrcode.settings'

During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Users\zubai\Downloads\SaveTreesQR\django-admin\manage.py", line 21, in <module>
        main()
      File "C:\Users\zubai\Downloads\SaveTreesQR\django-admin\manage.py", line 17, in main
        execute_from_command_line(sys.argv)
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
        utility.execute()
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\core\management\__init__.py", line 395, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\core\management\base.py", line 343, in run_from_argv
        connections.close_all()
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\db\utils.py", line 232, in close_all
        for alias in self:
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\db\utils.py", line 226, in __iter__
        return iter(self.databases)
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\utils\functional.py", line 48, in __get__
        res = instance.__dict__[self.name] = self.func(instance)
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\db\utils.py", line 153, in databases
        self._databases = settings.DATABASES
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\conf\__init__.py", line 83, in __getattr__
        self._setup(name)
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\conf\__init__.py", line 70, in _setup
        self._wrapped = Settings(settings_module)
      File "C:\Users\zubai\Downloads\SaveTreesQR\env\lib\site-packages\django\conf\__init__.py", line 177, in __init__
        mod = importlib.import_module(self.SETTINGS_MODULE)
      File "C:\Program Files\Python39\lib\importlib\__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
    ModuleNotFoundError: No module named 'qrcode.settings'

请注意,我已经完成了

pip install qrcode

pip install qrcode[pil]

pip install PyQRCode

来自 qr app 的 models.py 代码如下

 from django.db import models
from django import forms
from user.models import User
import datetime

# Class name starts with capital letter
class QR(models.Model):
    name = models.CharField(max_length=200, null=True, blank=True)
    description = models.CharField(max_length=255, blank=True)
    qr_identifier = models.CharField(max_length=255, blank=True)
    size = models.FloatField(default=0.0, blank=True)
    active = models.BooleanField(default=True, help_text='Active / Inacitve.')
    # TODO: Remove the default=1 parameter
    created_by_user = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
    created_at = models.DateTimeField(editable=False, auto_now_add=True)
    

class QRFile(models.Model):
    name = models.CharField(max_length=200, null=True, blank=True)
    location = models.FileField(upload_to='documents/')
    size = models.CharField(max_length=200, null=True, blank=True)
    media_type = models.CharField(max_length=200, null=True, blank=True)
    qr = models.ForeignKey(QR, on_delete=models.CASCADE)

class QRURL(models.Model):
    name = models.CharField(max_length=200, null=True, blank=True)
    URL = models.CharField(max_length=200, null=True, blank=True, default="Product Link")
    qr = models.ForeignKey(QR, on_delete=models.CASCADE)
    
class QRScan(models.Model):
    name = models.CharField(max_length=200, null=True, blank=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    qr = models.ForeignKey(QR, on_delete=models.CASCADE)
    scanned_at = models.DateTimeField(editable=False, default=datetime.datetime.now)
    comment = models.CharField(max_length=255, null=True, blank=True)
4

1 回答 1

0

您的项目被调用qrcode,因为 Django 的设置模块的默认路径是

<project name>.settings

在你的情况下转化为

qrcode.settings

Django 正在从qrcode库中导入设置。要解决此问题,请将您的项目重命名为与库名称不冲突的名称。

manage.py手动重命名项目后,您必须对wsgi.py文件进行适当的更改。

于 2020-11-16T21:44:52.553 回答