Commands and setup instruction for mysqlclient in django using ubuntu 20.04
[Note: Follow commands one by one in terminal]
-------------------------------------------------------------------------------------------------------------
Install python3.6 in ubuntu 20.04
sudo add-apt-repository ppa:deadsnakes/ppa
--------------------------------------------------------------------------------------------------------------
sudo apt-get update
--------------------------------------------------------------------------------------------------------------
sudo apt-get install python3.6
--------------------------------------------------------------------------------------------------------------
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 2
--------------------------------------------------------------------------------------------------------------
sudo update-alternatives --config python
---------------------------------------------------------------------------------------------------------------
Install a virtual environment in Ubuntu and create a venv for django and activate venv.
sudo apt-get install python3.6-venv
-----------------------------------------------------------------------------------------------------------------
python3.6 -m venv env
-----------------------------------------------------------------------------------------------------------------
pip install django==2.2
-----------------------------------------------------------------------------------------------------------------
source env/bin/activate
------------------------------------------------------------------------------------------------------------------
Install django, create application and runserver:
--------------------------------------------------------------------------------------------------------------------
pip install django==2.2
---------------------------------------------------------------------------------------------------------------------
django-admin startproject Test_Project
---------------------------------------------------------------------------------------------------------------------
python manage.py runserver
---------------------------------------------------------------------------------------------------------------------
Change database settings in settings.py
----------------------------------------------------------------------------------------------------------------------
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'HOST': 'localhost',
'PORT': '3306',
'USER': 'db_user',
'PASSWORD': 'db_password',
}
}
-----------------------------------------------------------------------------------------------------------------------
Install mysqlclient in venv using command as:
pip install mysqlclient
-------------------------------------------------------------------------------------------------------------------------
[Note: If error occurred while installing mysqlclient then give command in new terminal as:]
sudo apt-get install python3 python3-dev python3-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
Also Run:
sudo apt install libmysqlclient-dev
-------------------------------------------------------------------------------------------------------------------------
After this again try to give command as in No. ‘5’ your error will be solved.
-------------------------------------------------------------------------------------------------------------------------
0 Comments