I have cloned this repository as part of a tutorial and gone into the directory tango_with_django_19/code/tango_with_django_project to run the command:
$ python maange.py runserver
In order to run the web app. However, I received the following errors:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f6e2c1782f0>
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/usr/lib/python3.6/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/usr/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python3.6/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'registration'
I am using Manjaro Linux and have installed the packages python-django and python-django-extensions with pacman.
How can I resolve this error so that I can run the web app? I have not changed after cloning the aforementioned repo.
You need to install the project dependencies.
run pip install -r requirements.txt in tango_with_django_19/code to install them.
Then migrate and runserver
You're missing django-registration-redux package. It is specified in requirements.txt file as necessary to run project. You could install it via pip install -r requirements.txt
if you get the error after pip install django-registration-redux you can try easy_install django-registration-redux it worked for me.
Related
This week I started working home and tried installing my project on my PC but it won't work.
I cloned the git repo, installed MySQL Workbench and Server and stuff, installed Visual C++ stuffs
and loads of modules from my requirements.txt.
But when I try to run ./manage.py migrate it spits out this:
$ py manage.py migrate
Traceback (most recent call last):
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\db\backends\mysql\base.py", line 15, in <module>
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\lisa-\projects\register\manage.py", line 22, in <module>
main()
File "C:\Users\lisa-\projects\register\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\apps\config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\lisa-\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\contrib\auth\models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\contrib\auth\base_user.py", line 48, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\db\models\base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\db\models\base.py", line 326, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\db\models\options.py", line 207, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\utils\connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\utils\connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\db\utils.py", line 204, in create_connection
backend = load_backend(db['ENGINE'])
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\db\utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Users\lisa-\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\lisa-\projects\register\venv\lib\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
Now I did install mysqlclient:
$ pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.1.0-cp310-cp310-win_amd64.whl (180 kB)
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.0
All of this is happening with a newly made venv using python 3.10, Django 3.2.7 and SQL Server 8.0
I googled about 2 hours which didn't help at all, because all I could find was "use pip install mysqlclient", which I obviously did. Sometimes I find things like "install using a wheel file". But I can't find a wheel file for 3.10. Or "use pip install mysql-python" or something like that but then I get an error saying I need Visual C++ 14.0, which I'm pretty sure I have...
So, I'm lost. Please please help me out.
I'm Deploying a Django Application on an AWS instance (amazon2 64-bit, Linux/4.14.128-112.105.amzn2.x86_64). I spent a lot of time looking and searching in stack overflow without finding a solution.
My problem: correctly install mysqlclient.
The error:
mod_wsgi (pid=14418): Failed to exec Python script file '/var/www/html/project_x/project_x/wsgi.py'.
mod_wsgi (pid=14418): Exception occurred processing WSGI script '/var/www/html/project_x/project_x/wsgi.py'.
Traceback (most recent call last):
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: cannot import name '_mysql'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/var/www/html/project_x/project_x/wsgi.py", line 17, in <module>
application = get_wsgi_application()
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/models/options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/var/www/html/project_x/projectenv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 20, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
I've installed everything, but it doesnt work.
I created the virtual environment inside the projects folder:
$ virtualenv projectenv --python=python3.7
$ source projectenv/bin/activate
After that I've installed the plugins with pip:
$ pip list
Package Version
----------- -------
Django 2.2.5
mysqlclient 1.4.4
pip 19.2.3
pytz 2019.2
setuptools 41.2.0
sqlparse 0.3.0
wheel 0.33.6
As you can see, the packages are correctly installed. Also msqlclient is installed. I don't know what else to do, I've consulted a lot of posts on Stackoverflow, but none of them have solved my problem.
I have encountered same problem. I am not sure about AWS but I was having problem on my Mac. So what happens is that security of Mac do not let that settings access the file MySQLdb._mysql. So,I just run the command sudo cp -r /usr/local/mysql/lib/* /usr/local/lib/ and after running command python manage.py migrate, it worked. Hope my answer finds the solution you're looking for. Have a nice day!
I used the Django Rest Framework cookiecutter available here to scaffold a project. I've made no changes aside from setting up a virtualenv, installing requirements, and running pip install graphene_django. However, when I add graphene_django to the INSTALLED_APPS I receive the following error when attempting to run the server:
ModuleNotFoundError: No module named graphene_django
Any ideas why?
Traceback:
Traceback (most recent call last):
File "manage.py", line 24, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
Pip freeze:
...
graphene-django==2.0.0
...
Command to run app:
docker-compose up
The issue seems be related to Docker (or more specifically, me being unfamiliar with Docker). Running the docker-compose up --build command solved the issue. Hopefully, that helps someone else!
I recently pulled a repo from GitHub to get a local copy on my machine. The backend uses Django, and I was working on updating some models. Since I changed some models I wanted to run ./manage.py makemigrations. At first there was an issue with python2 vs python3, so I changed the #!/usr/bin/env python to #!/usr/bin/env python3. Then when I ran makemigrations, I get this:
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/Library/Frameworks/Python.framework/Versions/3.5/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 956, in _find_and_load_unlocked
ImportError: No module named 'autofixture'
Looking a bit further, I found out that this is because my settings.py file has autofixture, bootstrap3, and formtools in INSTALLED_APPS, but somehow my machine doesn't have those. I've tried to pip install all of them but the names autofixture, bootstrap3, and formtools aren't found in pip.
They are in pip, albeit not in those names; they are django-autofixture, django-bootstrap3 and django-formtools respectively.
So you can install them by typing:
pip install django-autofixture django-bootstrap3 django-formtools
Edit: Use pip3 instead of pip when using python3
pip3 install django-autofixture django-bootstrap3 django-formtools
I have been trying to set up a new django project locally with cookiecutter-django. I have followed the docs but I keep getting into errors when trying to run python manage.py migrate.
Error Traceback.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site- packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/local.py", line 11, in <module>
from .common import * # noqa
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/common.py", line 102, in <module>
'default': env.db('DATABASE_URL', default='postgres:///django_condominios'),
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/environ/environ.py", line 180, in db_url
return self.db_url_config(self.get_value(var, default=default), engine=engine)
File "/home/ubuntu/lasbrisas_project/venv/lib/python3.4/site-packages/environ/environ.py", line 371, in db_url_config
'PORT': _cast_int(url.port),
File "/usr/lib/python3.4/urllib/parse.py", line 156, in port
port = int(port, 10)
ValueError: invalid literal for int() with base 10: 'jd#uhUhey385'
I don't really know what I am doing wrong while setting up the project, I'd appreciate if you check the steps I took and help me find out what is missing.
Steps taken to setup the project with cookiecutter-django:
pip, virtualenv, PostrgreSQL already installed
pip install cookiecutter
cookiecutter https://github.com/pydanny/cookiecutter-django
Answer cookiecutter questions
Creating virtualenv - virtualenv -p /usr/bin/python3 venv
Activiting virtualenv - source venv/bin/activate/
cd intoprojectfolder
Docs say sudo ./install_os_dependencies.sh install but ./install_os_dependencies.sh is not in projectroot, file found in utility/
cd utility
sudo ./install_os_dependencies.sh install
pip install -r requirements/local.txt
Setting up db in postgresql:
sudo su - postgres
psql
CREATE DATABASE myproject;
CREATE USER myprojectuser WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
\q
Return tu project root
mv env.example .env
export DATABASE_URL=postgres://myprojectuser:myprojectuserdbpassword#127.0.0.1:5432/myproject
python manage.py migrate
After that is when I get the traceback, what could be going wrong? The docs show no more information, the migration should work.
Cookiecutter uses the slug of the project name as the name for the development db you are to use. You are expected to create the database yourself.
from your stacktrace here is the line giving you the problem from your settings.py file:
File "/home/ubuntu/lasbrisas_project/django_condominios/config/settings/common.py", line 102, in <module>'default': env.db('DATABASE_URL', default='postgres:///django_condominios'),
It expects to find a database named django_condominios.
You can fix this by running
createdb django_condominios
and you should be good run your migrations.