How to install python-mysqldb for Python 2.7 in Ubuntu 20.04 (Focal Fossa)? - python-2.7

I've tried "apt-get install python-mysqldb" which results in:
root#ps1svr:~# apt-get install python-mysqldb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package python-mysqldb is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'python-mysqldb' has no installation candidate
Note: "apt-get install python3-mysqldb" works, however I have a lot of code written for Python 2.x which no longer runs, and this is causing enough problems that I'm probably going to have to reinstall Ubuntu 18.04

Also you can just add the Ubuntu 18.04 repositoery to install the python-mysqldb package:
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu bionic main'
sudo apt update
sudo apt install -y python-mysqldb

This will download, build and install it for all users, using pip
sudo apt install libmysqlclient-dev python2.7-dev
wget https://bootstrap.pypa.io/get-pip.py
sudo python2.7 get-pip.py
sudo wget https://raw.githubusercontent.com/paulfitz/mysql-connector-c/master/include/my_config.h -O /usr/include/mysql/my_config.h
sudo pip2 install MySQL-python
Answer found from MySQLdb install error - _mysql.c:44:23: error: my_config.h: No such file or directory

Related

Unable to install pip

I tried installing pip in the following different ways and didn't have any success, any guidance how can I install pip ?
username#machine ~]$ sudo /usr/local/bin/easy_install pip
[sudo] password for username:
Searching for pip
Reading http://pypi.python.org/simple/pip/
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')
[username#machine ~]$ sudo /usr/local/bin/easy_install-2.7 pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')
[username#machine ~]$ python -m pip
/usr/local/bin/python: No module named pip
[username#machine ~]$ sudo apt-get install python-pip
sudo: apt-get: command not found
[username#machine ~]$ sudo yum install python-pip
Loaded plugins: security
Setting up Install Process
No package python-pip available.
Error: Nothing to do
Machine configuration:
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: OracleServer
Description: Oracle Linux Server release 6.6
Release: 6.6
Codename: n/a
You can try to use the following for python2.7:
sudo apt install python-pip
And if you alternatively want to install on python3:
sudo apt install python3-pip
None of the above worked, I had to do the following for OL7, as per the official docs:
yum install -y oracle-epel-release-el7 oracle-release-el7

How do I install babel.messages module in Ubuntu?

I am trying to install using
sudo apt-get install babel.messages
but getting error:
ImportError: No module named babel.messages
Please let me know how to install in Ubuntu 16.04
Try that with using this command:
# pip install babel
It will work well
For Ubuntu versions older than 17.04, you can install python-babel from the Ubuntu repositories by running the following command in terminal:
sudo apt-get install python-babel
For Ubuntu versions from 17.04 and also on older versions you can install it via pip, the Python package manager as:
pip install babel
If you don't have pip installed yet, you can install it as:
sudo apt install python-pip

Error while installing libapache2-mod-wsgi on linux

easy_install libapache2-mod-wsgi
No local packages or download links found for libapache2modwsgi
error: Could not find suitable distribution for Requirement.parse('libapache2mod wsgi')
libapache2-mod-wsgi is not a python package. You should install it via your distribution package manager. For example, if you are in a debian based distribution:
sudo apt-get install libapache2-mod-wsgi
Or if you are working with Python 3
sudo apt-get install libapache2-mod-wsgi-py3

Installing MySQL-python for Django

I've just learned how to use virtualenv and I installed Django 1.4.5. I'm assuming that the virtualenv created a clean slate for me to work on so with the Django 1.4.5 installed, I copied all my previous files into the virtualenv environment.
I tried to run the server but I get an error saying "no module named MySQLdb". I think this means that I forgot to install MySQL-python. I tried to install it via
pip install MySQL-python
But I get this error
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.24 (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))
Complete output from command python setup.py egg_info:
The required version of distribute (>=0.6.28) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.24 (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))
----------------------------------------
Command python setup.py egg_info failed with error code 2 in /home/bradford/Development/Django/django_1.4.5/build/MySQL-python
Not quite sure how to go about fixing this problem =/ any help much appreciated!
I recently had exactly this issue (just not in relation to Django). In my case I am developing on Ubuntu 12.04 using the default pip and distribute versions, which are basically a little out of date for MySQL-python.
Because you are working in an isolated virtualenv, you can safely follow the suggested instruction without affecting your Python installation.
So you can...
workon your_virtualenv #activate your virtualenv, you do use virtualenvwrapper, right?
easy_install -U distribute #update distribute on your virtualenv
pip install MySQL-python #install your package
If for some reason upgrading distribute is not an option, you could try installing an older version of MySQL-python as follows (you'd have to check this version is compatible with your version of Django):
pip install MySQL-python==x.y.z #where x.y.z is the version you want
Spent an hour looking through stackoverflow. Evntually found answer in the other question. This is what saved me:
sudo apt-get install libmysqlclient-dev
mysql_config goes with the package.
When doing in a virtualenv :
pip install MySQL-python
I got
EnvironmentError: mysql_config not found
To install mysql_config, as Artem Fedosov said, first install
sudo apt-get install libmysqlclient-dev
then everything works fine in virtualenv
MySQL driver for Python (mysql-python) needs libmysqlclient-dev. You can get it with:
sudo apt-get update
sudo apt-get install libmysqlclient-dev
If python-dev is not installed, you may have to install it too:
sudo apt-get install python-dev
Now you can install MySQL driver:
pip install mysql-python
Here is a more detailed documentation for MySQL in Django:
http://codex.themedelta.com/how-to-install-django-with-mysql-in-a-virtualenv-on-linux/
I had to do this:
pip install mysql-python
inside the virtualenv
The commands are always run in ubuntu:
easy_install -U distribute
later
sudo apt-get install libmysqlclient-dev
and finally
pip install MySQL-python
The suggested solutions didn't work out for me, because I still got compilation errors after running
`$ sudo apt-get install libmysqlclient-dev`
so I had to run
apt-get install python-dev
Then everything worked fine for me with
apt-get install python-dev
Try this:
Version Python 2.7
MySQL-python package, you should use either MySQL_python‑1.2.5‑cp27‑none‑win32.whl or
MySQL_python‑1.2.5‑cp27‑none‑win_amd64.whl depending on whether you have installed 32-bit or 64-bit Python.
pip install MySQL_python‑1.2.5‑cp27‑none‑win32.whl
if you are using mysqlclient package, then use
mysqlclient‑1.4.6‑cp27‑cp27m‑win32.whl or
mysqlclient‑1.4.6‑cp27‑cp27m‑win_amd64.whl
pip install mysqlclient‑1.4.6‑cp27‑cp27m‑win32.whl
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

django_auth_ldap no module named ldap

I am trying to get the django_auth_module working but I don't think I managed to install it properly.
I downloaded the package and ran setup.py install.
Then in my settings.py file I tried to import the module ldap and it gave me the following error :
ImportError: no module named ldap
I am working on a CentOS 6 server.
Maybe it has to do with where I should install the module? The folder is in the directory just above my site folder, but maybe that's wrong...
RESOLVED :
Ok, I just needed to install the module python-ldap... problem solved!
Install missing module
Hint: To install python-ldap with pip on Ubuntu, some libraries are needed.
Use the apt-get commands to install them.
Python 2
sudo apt-get install python-dev libldap2-dev libsasl2-dev libssl-dev
sudo pip install python-ldap
Python 3
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
sudo pip3 install pyldap
Try the below command to install for Python3.
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
sudo pip3 install pyldap