Python-MySQLdb Error in Ubuntu - python

I am trying to setup the environment in Ubuntu (making a shift from
MS-Windows).
It has, of course, Python 2.6.
I did setup MySQL 5512 and MySQLdb from 'Ubuntu Software Centre'.
import dabo
import MySQLdb
works OK. No error.
But while establishing a connection, is says that there is a mismatch in
versions of MySQLdb & _mysql.
ImportError: this is MySQLdb version (1, 2, 3, 'gamma', 1), but _mysql
is version (1, 2, 2, 'final', 0)
How do I solve this?
Complete traceback ---->
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "dabovmd/hotel.py", line 4, in <module>
empconn = dabo.db.dConnection(empci)
File "dabo/db/dConnection.py", line 32, in __init__
self._connection = self._openConnection(**kwargs)
File "dabo/db/dConnection.py", line 80, in _openConnection
return
self._connectInfo.getConnection(forceCreate=self._forceCreate, **kwargs)
File "dabo/db/dConnectInfo.py", line 105, in getConnection
return self._backendObject.getConnection(self, **kwargs)
File "dabo/db/dbMySQL.py", line 25, in getConnection
import MySQLdb as dbapi
File "/media/pyth/python26/Lib/site-packages/MySQLdb/__init__.py",
line 23, in <module>
(version_info, _mysql.version_info))
ImportError: this is MySQLdb version (1, 2, 3, 'gamma', 1), but _mysql
is version (1, 2, 2, 'final', 0)
Thanks in advance,
Vineet

This seems like a version mismatch between your MySQL-server and your python-mysqldb.
Which version of Ubuntu are you using? (If you have recently shifted over, then try using Ubuntu 11.04).
The easiest way to solve your problem would be to update your ubuntu to atleast 11.04 and then to install matching versions of mysql-server and python-mysqldb.
I am using Ubuntu 11.04 and my mysql-server version is 5.1.54-1ubuntu4 and my python-mysqldb version is 1.2.2-10build2.
Hope this helps

This may not be suitable for your needs, but I've found MySQL Connector/Python to be much much easier to set up than MySQLdb. It's implemented entirely in Python, so it doesn't care about the C interface libraries.
This solution has a couple of downsides. It's supposed to be slower. And more importantly in your case, I know nothing about Dabo so I have no idea if it's possible to sub in a different MySQL interface.

It seems that each of apt-get and pip installed their own version of the library.
Try removing system mysql with sudo apt-get remove python-mysqldb, and
you should have something like this:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
python-mysqldb
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 196 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 109333 files and directories currently installed.)
Removing python-mysqldb (1.2.3-2ubuntu1) ...

Please don't do what has been suggested above...
use these commands in your MySQLdb folder:
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
sudo python setup.py install

Related

ipython3 does not work in the terminal with python3.7

I recently upgraded from Python3.6 to Python3.7. Since I have upgraded, when I type in ipython3 in the terminal I get an error:
~$ ipython3
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/IPython/__init__.py", line 48, in <module>
from .core.application import Application
File "/usr/lib/python3/dist-packages/IPython/core/application.py", line 25, in <module>
from IPython.core import release, crashhandler
File "/usr/lib/python3/dist-packages/IPython/core/crashhandler.py", line 28, in <module>
from IPython.core import ultratb
File "/usr/lib/python3/dist-packages/IPython/core/ultratb.py", line 124, in <module>
from IPython.utils import path as util_path
File "/usr/lib/python3/dist-packages/IPython/utils/path.py", line 18, in <module>
from IPython.utils.process import system
File "/usr/lib/python3/dist-packages/IPython/utils/process.py", line 19, in <module>
from ._process_posix import system, getoutput, arg_split, check_pid
File "/usr/lib/python3/dist-packages/IPython/utils/_process_posix.py", line 24, in <module>
import pexpect
File "/usr/lib/python3/dist-packages/pexpect/__init__.py", line 75, in <module>
from .pty_spawn import spawn, spawnu
File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 14, in <module>
from .spawnbase import SpawnBase
File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 224
def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
^
SyntaxError: invalid syntax
Furthermore I have noticed that my jupyter-notebook does not seem to work with the python3 kernel now as well (I get the kernel dead error).
NOTEs:
ipython and jupyter-notebook are working with fine when I use them with Python2.
I am using Ubuntu 18.04 (Bionic Beaver) although I don't think this is relevant
async is a reserved keyword in python3.7 and an old version of pexpect is using async as variable. The solution is to upgrade pexpect.
For me, it was conflicting with apt-get installed python3, so I had to first uninstall it/them:
sudo apt-get remove python-pexpect python3-pexpect
And then
sudo pip3.7 install --upgrade pexpect
UPDATE Please update your installed packages.
This error for pexpect has been reported and closed already issue
In Python 3.7, async and await are now reserved keywords. This is what is breaking some of your installed packages.
If you do not need the new features in 3.7, roll back to 3.6 and wait until your packages are updated to support the new syntax in 3.7
What's New in Python 3.7
I just solve this problem by upgrading pexpect manually.
Download pexpect4.6 source code from https://github.com/pexpect/pexpect/releases/tag/4.6
Extract the source code, get into the folder and install the pexpect by:
sudo python3.7 setup.py install
As others have noted, having the current version of the pexpect package should solve this. In my case, the python3-pexpect package that I had installed through apt was stuck on an old version and I first had to remove it. Then installing the current pexpect package through pip3 fixed the problem.
This appears to be an issue related to async being keyword in Python 3.7
As given here, updating pipenv might be the solution
async is a reserved word in Python 3.7
You can edit the packages yourself if you feel comfortable doing it.
Here is a shell command that does just that:
sed "s/async/_async/g" "/usr/lib/python3/dist-packages/pexpect/spawnbase.py" > tmp.txt && cat tmp.txt > "/usr/lib/python3/dist-packages/pexpect/spawnbase.py" && rm tmp.txt
Otherwise, you might want to use Python 3.6 while waiting for an update.

Required files to run Scrapy in Mac OS x 10.7.5, using Python 2.7.3 IEPD_free (32 bit)

I am testing scrapy for the first time, and after installing it with the command:
sudo easy_install -U scrapy
everything seems to run ok. However, when I run:
scrapy startproject tutorial
I get the following:
luismacbookpro:~ luis$ scrapy startproject tutorial
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/Current/bin/scrapy", line 4, in <module>
import pkg_resources
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pkg_resources.py", line 2711, in <module>
working_set.require(__requires__)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pkg_resources.py", line 690, in require
needed = self.resolve(parse_requirements(requirements))
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pkg_resources.py", line 588, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: lxml
Any idea about what's going on? As you can tell, I am not proficient at all with OSX, and I am still trying to move from a windows "mentality" to OSX, so I don't know where to add paths, modify settings, dependencies, etc. Not even sure how to perform a clean uninstall and start all over.
Any feedback is appreciated, even your suggestions to use alternative python libraries that can perform the same functionality of scrapy. Thanks!
I think this will solve the error message you're seeing:
sudo easy_install --upgrade lxml
This problem can arise on Macs when you use pip to install some packages and easy_install to install others.
Let us know how you go :)

Installing MySQL for python/Django

I'm trying to use MySQL with django and right now the following isn't executing properly:
python manage.py syncdb
I also downloaded the Mysql-python interpreter and ran the following lines but still an error:
python setup.py build
sudo python setup.py install
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "/Users/user/Downloads/MySQL-python-1.2.3/setup_posix.py", line 49, in get_config
libs = mysql_config("libs")
File "/Users/user/Downloads/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: /usr/local/bin/mysql_config not found
I think it's having trouble finding mysql_config, is there a way that I can point the setup to the file? Right now my setup.py is in ~/Downloads and mysql is in /usr/local/mysql/bin
It seems you may not have any of the MySQL client applications installed. If you are using Linux (and this varies from distribution to distribution), the package you will need to install on Ubuntu is "mysql-client".
From the path you show, I'm guessing you are running on Mac OS X (you really need to state what platform you are using and what version of Python you are running). However, if you are on Mac OS X, your best bet by far is to use a complete solution of installing compatible versions of Python, MySQL client libraries, MySQLdb, and Django by using one of the third-party open source package managers on OS X: MacPorts, homebrew, Fink, or others.
See, for example, the answer here.
The answer was to edit the site.cfg file so that it points to the mysql_config file in the /usr/local/mysql dir

Error when installing mysqldb

When installing mysqldb on mac osx 10.5:
sudo ../bin/python /Users/Awais/mysqlpython/setup.py install
I get the following error:
Traceback (most recent call last):
File "/Users/Awais/mysqlpython/setup.py", line 15, in <module>
metadata, options = get_config()
File "/Users/Awais/mysqlpython/setup_posix.py", line 32, in get_config
metadata, options = get_metadata_and_options()
File "/Users/Awais/mysqlpython/setup_common.py", line 7, in get_metadata_and_options metadata = dict(config.items('metadata'))
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/ConfigParser.py", line 564, in items
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'metadata'
It seems that you are installing MySQL for Python but you have to have MySQL installed first. So, first download the MySQL installer from http://dev.mysql.com/downloads/mysql/ and install it and then try installing MySQL for Python.
I am trying port an older Linux server RH EL 5 Workstation to CentOS 6.4 64-bit. One of the two things I have had to do -- because it had been a while since I had built a Python-based MySQL server -- was make sure mysql-devel was installed, and from the menu-software install, as well as MySQL-python was installed.
The advantage to installing MySQL-python this way that the CentOS 6.4 distribution matches MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 matches the version of MySQL installed 5.1.69.
Prior to this, I tried building and installing MySQL-python with no success. In a perfect world, I would figure out why, but, like many things, I am on a deadline, and this worked, and was also recommended in posts I read both on SO and elsewhere.

How should I handle software packages?

I am trying to install pysqlite and have troubles with that. I found out that the most probable reason of that is missing sqlite headers and I have to install them. My platform: CentOS release 5.3 (Final). I have Python-2.6.2.
I also found out that I need .rpm files. As far as I have them I execute:
rpm -i sqlite3-devel-3.n.n.n.rpm
and everything should be fine.
However, I do not know where to find sqlite3-devel-3.n.n.n.rpm file. Should it already be on my system? I could not locate it with "locate sqlite3-devel-3". Should I download this file? If yes where I can find it and which version should I use? I mean, the .rpm file should be, probably, consistent with the version of sqlite that I have on my computer? If it is the case, how can I find out the version of my sqlite?
If I type "from pysqlite2 import dbapi2 as sqlite" I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pysqlite2
"yum search pysqlite" gives me the following:
Loaded plugins: fastestmirror
Excluding Packages in global exclude
list Finished
==== Matched: pysqlite ==== python-sqlite.x86_64 : Python bindings
for sqlite.
By the way, I have the following directory:
/home/myname/opt/lib/python2.6/sqlite3
and there I have the following files:
dbapi2.py dbapi2.pyc dbapi2.pyo
dump.py dump.pyc dump.pyo
__init__.py __init__.pyc __init__.pyo test
If I type "import unittest" and then "import sqlite3 as sqlite" I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/myname/opt/lib/python2.6/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import * File "/home/myname/opt/lib/python2.6/sqlite3/dbapi2.py",
line 27, in <module>
from _sqlite3 import * ImportError: No module named _sqlite3
Thank you in advance.
Python 2.6 (and some earlier) include sqlite Python org library ref so you should not need to do this. Just import it and run
You can use buildout to create localized version of your project. This will install all necessary packages without having sudo access to the server.
To give it try, do the following:
mkdir tmp
cd tmp
wget http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py
python bootstrap.py init
vim buildout.cfg
edit buildout.cfg and replace it with following:
[buildout]
parts = sqlite
[sqlite]
recipe = zc.recipe.egg
eggs = pysqlite
interpreter = mypython
Now, run ./bin/buildout to rebuild the project. This will download all of the necessary packages and create a new interpreter for you that you can use test that you can access sqlite.
./bin/buildout
./bin/mypython
>>> import sqlite3
This gives you a controlled environment that you can use to develop inside of.
To learn more about buildout, you can watch videos from pycon 2009 on Setuptools, Distutils and Buildout.
Eggs and Buildout Deployment in Python - Part 1
Eggs and Buildout Deployment in Python - Part 2
Eggs and Buildout Deployment in Python - Part 3
Good luck
Typically, you should install the python sqlite module through yum, something like:
yum install python-sqlite
and then edit your code changing sqlite2 references to sqlite3.
By the way, whenever you read directions to install sqlite3-devel-3.n.n.n.rpm, the n parts are not literal; they're supposed to be replaced with numbers specifying a version of the rpm package.

Categories

Resources