0

I am trying to set up a new project on my windows 10 64 bit pc

While doing python manage.py makemigrations I keep getting ModuleNotFoundError: No module named 'qrcode.settings'

I have installed all the dependencies successfully, running the cmd in venv.

I looked for this particular issue, but couldn't find the solution. I am using Python 3.9.

The dependencies are (pip freeze)

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',

]

The error is as follows

    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'

Please note, I already have done

pip install qrcode

pip install qrcode[pil]

pip install PyQRCode

models.py code from qr app is as follows

 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)
Zubair Khan
  • 11
  • 1
  • 4
  • why ii didnt list in requirements (attach your `pip freeze`)? where do you you use it? show your apps.INSTALLED_APPS ... be specific, we cannot debug your local project – madzohan Nov 16 '20 at 17:04
  • Hi @madzohan I edited the question. I am a newbie. – Zubair Khan Nov 16 '20 at 17:20
  • Is QR code a Django app or just a package your Django project needs? Is your project structure unusual / unconventional? – Jarad Nov 16 '20 at 17:37
  • @Jarad pyqrcode and qrcode are both packages. In the this Django project 'qr' is also an app. When I do pip install qrcode ..it gets installed properly all the dependencies in pip freeze are installed correctly -- its just that while running migration it says qrcode.settings not found – Zubair Khan Nov 16 '20 at 17:40
  • 1
    I suppose it used in 'qr' & 'qradmin' apps which included in INSTALLED_APPS (thats why django trying to import modules) could you show `models.py` code from `qr` app, so we can try to reproduce? – madzohan Nov 16 '20 at 17:51
  • also you could temporary comment out these two apps from INSTALLED_APPS and run migrate without them to make sure everything else creating in database – madzohan Nov 16 '20 at 17:55
  • @madzohan I edited the question to include models.py from qr app – Zubair Khan Nov 16 '20 at 17:57
  • @madzohan .. ok let me comment out these 2 apps and try to run the migration – Zubair Khan Nov 16 '20 at 17:57
  • @madzohan Tried commenting these two apps. But issue is same. qrcode.settings not found – Zubair Khan Nov 16 '20 at 18:01

1 Answers1

0

Your project is called qrcode and since default path for settings module of Django is

<project name>.settings

which in your case translates to

qrcode.settings

Django is importing settings from qrcode library. To fix this issue, rename your project to something that does not conflict with the library name.

After you manually rename the project, you have to make appropriate changes in manage.py and wsgi.py files.

Borut
  • 3,304
  • 2
  • 12
  • 18