I am trying to link postgresSQL with my django framework.
My db settings in settings.py are
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'tutorial',
'USER': 'vibhor',
'PASSWORD': 'vibhor',
'HOST': '',
'PORT': '',
}
}
I ran pip install psycopg2 and it got installed successfully. But when I run the program, I faced the error below. I am using python version 3.7.2 on windows 10 Enterprise
I am getting same error again and again -
ModuleNotFoundError: No module named 'psycopg2'
Related
trying to connect to the mysql and trying to do makemigrations. but getting this error:
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.mysql' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'oracle', 'postgresql', 'sqlite3'
my settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '****',
'USER': 'root',
'PASSWORD': '****',
"HOST": '****',
'PORT': '****'
}
}
Thanks in advance
It can be solved by removing virtual environment and reinstalling all the packages again,
then you can have access to mysql database
Following the reinstalling packages advice, which worked for me:
pip uninstall -y `pip freeze`
pip install -r requirements.txt
If you do not have a requirements file already you can create it with pip freeze > requirements.txt
I'm trying to connect to MySQL database from a Django project and I have this error: "django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?".
I have already installed mysqlclient with this command:
pip install mysqlclient
In my Django project's settings.py file I have changed the database to this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_django',
'USER': 'root',
'PASSWORD': '',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
I'm using Visual Studio Community 2019. Django version: 2.2.9. Python version: 3.8.1 & Xampp for the MySQL.
Any help would be appreciated!
I installed the psycopg2-binary package using pip install psycopg2-binary. But when how can I use it in Python?
import psycopg2 as pg2
conn = pg2.connect(database = 'dvdrental', user = 'postgres', password = secret)
cur = conn.cursor()
cur.execure('select * from actor')
cur.fetchmany(5)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-6-c2276cd20949> in <module>()
----> 1 import psycopg2 as pg2
2 conn = pg2.connect(database = 'dvdrental', user = 'postgres', password = secret)
3 cur = conn.cursor()
4 cur.execure('select * from actor')
5 cur.fetchmany(5)
ModuleNotFoundError: No module named 'psycopg2'
I'm using Django on a Mac. This is what worked for me.
In my virtual environment I ran:
pip install psycopg2-binary
In settings.py I specified:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
The database credentials have been left off. I understand this isn't what the OP was asking about, but hopefully it will be helpful to someone.
First install the dependencies,
sudo apt-get install build-dep python-psycopg2
And after that,
pip install psycopg2
Ubuntu/Debian
pg_config is usually installed by libpq-dev.
More details: https://www.psycopg.org/docs/install.html
Mac OS X
Try using Brew Package manager for macOS(or Linux)
https://brew.sh/
brew install postgresql
And if installed Postgres.app
Then update the PATH as
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/14/bin
Version can be checked via Applications->Postgres.app->Show Package Content->Contents->Versions->14
Afterwards do
pip install psycopg2
(windows server 2008 r2) python 34,
I changed settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
1) I run the command:
python manage.py migrate
i get an error:
error loading mysqldb module django.core.exception error loading mysqldb
2) I run the command:
pip install mysql -python
get "failed building wheel for mysql-python microsoft visulal c++ 2010 is required unable to find vcvarsall.bat
3) visual c++ 2010 was installed
I have in system variable path to:C:\Python34\Scripts;C:\Python34;
Furthermore i success to run commands from python to mysql (create\read\write table)
what else can i do in order the command python manage.py migrate will work?
You can use mysqlclient , it supports Python3 .You can read about it in django docs.
If
pip install MySQL-python
is failing, you can try easy_install MySQL-python.
Also install this: sudo apt-get install python-mysqldb
Solved by running the following command:
pip install mysqlclient
Trying to python manage.py syncdb but it gives me an error. Similar to a lot of other questions on here, but the solutions provided do not solve the error after I install them.
My settings.py file inside my project directory
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'network',
'USER': 'root',
'PASSWORD': 'mypass',
'HOST': '', #EMPTY FOR LOCALHOST
'PORT': '3307', #Empty by default
}
}
I am using Windows 7, Python 3.4 (I heard was not compatible with install MySQL-python so instead I downloaded mysqlclient 1.3.6).
When I ran easy_install mysql-python it results in
_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: Setup script exited with error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\BIN\\cl.exe'
failed with exit status 2
Similarly it asks for config-win.h when running pip install mysql-python, along with a scary error
Command "D:\Users\Python\python.EXE -c "import setuptools, tokenize;__file__='C:\\Users\\AppData\\Local\\T
emp\\pip-build-w7q9kjxi\\mysql-python\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('
\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\AppData\Local\Temp\pip-u982sugf-record\install-record.t
xt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\AppData\Local\Temp\pip-build
-w7q9kjxi\mysql-python
I'm pretty confused about this. The tutorial I've been looking at strays from me here, and I have no idea what to do with a WHL of mysqlclient.
Things I've tried already:
easy_install Distribute works but does not change anything
python manage.py syncdb no module named 'MySQLdb'
apt-get install python-mysqldb term 'apt-get' not recognized at all.
Please help with this beginner question, thanks for your time, if more info is needed I'd be happy to provide.
Without Visual Studio, you'll need a binary installer for the right Python version and architecture. The easiest is probably to get both 32- and 64- bit packages for the installed Python version and install them both.
I had the same error working on Windows, I solved it by downloading apart and then copying theMySQL_python-1.2.5-py2.7.egg-info and the MySQLdb folders and the _mysql.pyd and _mysql_exceptions.py files in C:\Users\%The-path-of-your-project%\Lib\site-packages