I'm trying to deploy a flask app in a centOS 7.
I installed the connector with: sudo yum install mysql-connector-python
But when I run: python init.py, I got this error:
from mysql import connector
ImportError: No module named mysql
Note: my project is inside a virtualenv.
Inside my virtualenv:
pip install MySQL-python
Error:Requirement already satisfied (use --upgrade to upgrade): MySQL-python in /root/ams/env/lib/python2.7/site-packages
yum install MySQL-python
Error:Package MySQL-python-1.2.3-11.el7.x86_64 already installed and latest version
you can run this :
sudo yum install mysql-connector-python-rf
Not sure about the reason but probably the mysql connector you installed is not imported into your virtualenv.
Do the following to see the lib paths:
(virtualenv) $ python
>>> import sys
>>> sys.path
And search for each path for mysql directory.
UPDATE
If you decide to use MySQL-python instead of mysql-connector-python you can follow its document here.
My recommendation is to use some db layer like SQLAlchemy but if you want to connect to mysql manually here's a good tutorial.
How do I connect to a MySQL Database in Python?
Related
I've build a django project using python 3.7, Now I'm trying to deploy my project on Google App engine, and trying to use mysql locally for testing. After going through multiple question/answers/documentation still I'm unable to install mysql correctly.
I tried following options:
pip install mysqlclient
brew install mysql-connector-c
pip3 install http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.zip
pip install mysql-connect-python
pip install pymysql
But none of the above is working for me.
I am setting a new Django 2.2 project with MySQL 8.0 on mac. I already installed mysqlclient and mysql-connector-python. When I hit python manage.py makemigrations this displayed:
"django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?"
I am using python 3.7.
How can I solve this problem?
I already installed pip install mysqlclient mysql-connector-python
Will not work for Python 3.7
import pymysql
pymysql.install_as_MySQLdb()
You need to install mysqlclient globally and in your project. I think you should install once globally on your pc and try
So I'm trying to follow a tutorial to connect to an SQL database, using Connector/Python.
I have to import it, obviously:
import mysql.connector
So I tried pip install mysql in the terminal.
This is what I got:
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/g6/yrxcmygn3ls375rm9rh3p86r0000gn/T/pip-build-a0d0rzdl/MySQL-python/
What I've tried from looking up on Google:
pip install --upgrade setuptools
pip install ez_setup
pip install unroll
easy_install -U setuptools
Nothing worked
Thanks
MySQL-Python is not available for Python 3, you may consider using MySqlClient which is a fork of the MySQL-python interface for the MySQL database.
Before installing this connector, make sure MySQL (or MariaDB) is installed.
On Linux, you also need the "devel" packages. See: https://stackoverflow.com/a/7461662/1513933
On Windows, you may be interested in the unofficial Windows binaries.
To install, an application, the best practices is to use a virtualenv.
I have error to connect existing mysql database in python and i unable to do
pip install mysql command
import MySQLdb
db = MySQLdb.connect(host='10.10', port=3306, user='system', passwd='xyz' db='Reporting')
print(db)
I want to retrieve the data from mysql database in python.
Use pip install MySQL-python instead
You need to install the dependencies before installation with pip.
apt-get install python-dev libmysqlclient-dev
And than, the installation with pip like the answer of Zart should work.
pip install MySQL-python
The above answer is only for Linux System.
For Windows you can download the .whl file from here mysqlclient and install it. Please download the right version. win32 for 32 bit. amd64 for 64 bit. cp27 for python 2.7, cp34 for python 3.4, cp35 for python 3.5
I am new to django
I would like to start a project but when i run it i get this error
Error loading MySQLdb module
How do i add the MYSQL module or any other module for that matter
Install it on your system, using either a native installer or package, via pip or easy_install, or by running setup.py in the tarball.
you should install a mysql client and a mysql python client for that client. So you should execute following commands(For Debian systems)
apt-get install mysql-client
apt-get install python-mysqldb