Adding database module - python

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

Related

Error starting DJango server when installing Mysql

I just started to create a new project with Django.
I have installed MySql and MySql client for Python.
But this error happens when I try to run the server.
sudo apt-get update
sudo apt-get install mysql-server
sudo apt-get install python-mysqldb
ModuleNotFoundError: No module named 'MySQLdb'
........
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?``
SOLVED. I needed to use install the mysqlDB with python3.
But now this error appears.
Someone?
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required;
you have 1.3.10.
You need to install mysql-client, not mysql-python.
Try to install mysql-client and you will find many mysql-client wheels.
Download the first one, do not change the name of the file
open command prompt
use cd to go to the directory where your wheel has been installed
then use pip install (name of file) #use .whl as well
if it doesn't work, download the second one and repeat the process, if that doesn't work as well, keep on downloading until I guarantee you that at least one of them would be installed in your computer

How to configure pymssql with SSL support on Ubuntu?

What were the steps required to configure (the now discontinued) pymssql with SSL support on Ubuntu so I can connect to a SQL Server instance that requires an encrypted connection (e.g., Azure)?
Ubuntu 16.04 LTS
(See this answer for Ubuntu 18.04 LTS.)
The following worked for me on a clean install of Xubuntu 16.04 LTS x64:
The first challenge is that the FreeTDS we get from the Ubuntu 16.04 repositories does not support SSL "out of the box", so we need to build our own. Start by installing python3-pip (which also installs build-essentials, g++, and a bunch of other stuff we'll need) and libssl-dev (the OpenSSL libraries required for building FreeTDS with SSL support)
sudo apt install python3-pip libssl-dev
Download the source code for FreeTDS by clicking the "Stable Release" link at freetds.org. Unpack the archive, switch to the directory you just created (e.g., freetds-1.00.104), and then do
./configure --with-openssl=/usr/include/openssl --enable-msdblib
make
sudo make install
Check the build with
tsql -C
and ensure that "TDS version: auto" and "OpenSSL: yes" are listed. Then use tsql to test a "raw" FreeTDS connection, e.g.,
tsql -H example.com -p 1433 -U youruserid -P yourpassword
Now to install pymssql. By default, recent versions ship as a pre-compiled "wheel" file that does not support encrypted connections so we need to install from the pymssql source. Starting with pymssql 2.1.4, the build process relies on Cython, so first do
pip3 install --user Cython
and then do
pip3 install --user --no-binary pymssql pymssql
When the build is complete, pymssql is installed.
But... it won't work (yet). When we try to do import pymssql in Python we get
ImportError: libsybdb.so.5: cannot open shared object file: No such file or directory
because apparently that file is in the "wrong" place. The fix (ref: here) is to create a symlink in the "right" place that points to the actual file
sudo ln -s /usr/local/lib/libsybdb.so.5 /usr/lib/libsybdb.so.5
sudo ldconfig
Now pymssql works with SSL connections.
For me, anyway.
Ubuntu 18.04 LTS
The Ubuntu 18.04 repositories will install a version of FreeTDS that supports GnuTLS so it is not absolutely necessary to build FreeTDS from source. However, we still need to build pymssql from source because simply doing the usual
pip3 install --user pymssql
will install a pre-compiled "wheel" that does not support secure connections. Instead, we need to do
sudo apt install python3-pip freetds-dev
pip3 install --user Cython
pip3 install --user --no-binary pymssql pymssql
For Ubuntu 16.04 it seems that at least the Docker containers have a FreeTDS version that already supports SSL.
Also, at least for Python 2.7, Cython is not needed:
https://github.com/tds-fdw/ci-setup/blob/master/ubuntu16.04/Dockerfile (lines 23-39)
But there's something to keep in mind!
The TDS version to connect to Azure must be forced to be at least 7.1 (or newer, depending on your needs: https://www.freetds.org/userguide/choosingtdsprotocol.htm)
Otherwise you will see the infamous:
[ERROR] (20017, 'DB-Lib error message 20017, severity 9:\nUnexpected
EOF from the server\nNet-Lib error during Operation now in progress
(115)\nDB-Lib error message 20002, severity 9:\nAdaptive Server
connection failed\n')
For some reason this was not needed for Ubuntu 14.04 and pymssql 2.1.3 without any extra configuration (https://github.com/tds-fdw/ci-setup/blob/master/ubuntu14.04/Dockerfile)
It can be done with either:
export TDSVER=7.1
Or, at the Python code, and at the connect function, adding the parameter:
tds_version='7.1'
With that, I am able to to use pymssql 2.1.4 to connect to Azure without issues.
you can use pymssql:2.2.0
first uninstall old pymssql:
sudo pip3 uninstall pymssql
second install new pymssql:
sudo pip3 install "pymssql==2.2.0"

MySQL connector in centOS 7

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?

Python - install Pillow and MySQL-python on 1and1 hosting

I've created python virtual environment, installed django using pip and now I would like to install Pillow and MySQL-python using pip but it fails during compile process.
(starting with python.h no such file or directory)
Has anyone tried intall some of these on 1and1 hosting ?
Maybe compile it on different machine or other solution ?
There's not really enough detail here to help. But one possibility is that you don't have the development package for python installed. If you are using Debian or Ubuntu, you can do sudo apt-get install python-dev to install it.

paramiko installation " Unable to import ImportError"

I installed paramiko in my Ubuntu box "sudo apt-get install python-paramkio".
But when import the paramiko module i am getting error.
ImportError:No Module named paramiko
When i list the python modules using help('modules'). i couldn't find paramiko listed.
To use python libraries, you must have development version of python like python2.6-dev, which can be installed using sudo apt-get install python2.6-dev.
Then you may install any additional development libraries that you want in your code to run.
Whatever you install using sudo apt-get install python-paramkio or python setup.py install will then be available to you.

Categories