SQLAlchemy stops working with MySQLdb out of nowhere - python

For the past couple days, it's been working fine. But today, I was trying fix some encoding issue, and it just suddenly stopped working. I reverted my code back to what it was like from before, but for some reason the error is still there. (And so is the encoding issue, sadly.)
I am using MySQL with MySQLdb on Python 3.6.2 and Anaconda. I am aware of MySQLdb's incompatibility with Python 3 and with Anaconda. However, I do not want to use Python 2 or a different driver.
I have worked around this by installing mysqlclient, and I am able to do import MySQLdb in the Qt console. I was also able to create an engine with below code literally 30 minutes ago.
from sqlalchemy import create_engine
engine = create_engine('mysql://user:pass#localhost:3306/db?charset=utf8')
I checked my code with the one I had on the remote repo just to make sure there was no mistake. It's exactly the same. Yet now I'm getting the following error:
NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:mysql
Which seems very odd considering that I have both. This error is seen when I run my script in the Qt console with %run myscript.py. I've been doing that since yesterday without any issues.
I am not using any virtual environments as I found it a pain to manage them on Windows and with Anaconda. I also checked that MySQLdb is importable in the console before running the script. So I know the module is properly installed.
I tried to figure out what's going on, and during my investigation I found out that I'm missing sqlalchemy.connectors module, but I'm not sure if that actually is an issue because I can't find any similar issues online. Here's what I did to get that error:
from sqlalchemy.dialects import mysql
ModuleNotFoundError: No module named 'sqlalchemy.connectors'
Does anyone know what the issue is? This is really frustrating because this seems to be completely out of blue :/
** I just tested whether other drivers work (i.e. pymysql), and it doesn't. I think it's because sqlalchemy is rejecting the dialect regardless of the driver.
EDIT: To reproduce (at least on my machine at the moment) I only need 2 lines.
from sqlalchemy import create_engine
engine = create_engine('mysql://user:pass#localhost:3306/db')
EDIT2: I identified it as an Anaconda issue, however I'm still unsure what the cause is.

Clean reinstall of sqlalchemy have fixed the issue.
Can't believe that wasn't the first thing I tried.
I still have no idea how it got corrupted, though.
$ conda uninstall sqlalchemy
$ conda install sqlalchemy

Related

db.create_all() issues with python 3.7 for MAC

I can tell many people have had issues with this but having tried all possible solutions i have made my own post which hopefully can help solve this issue specifically for me.
When i try running db.create_all() i get this error (attached in pic):
Error observed
I understand this is because mysqldb does not support python 3. But i have also tried importing the pymysql and this didnt work either (unless of course i did that step wrong? I basically added the lines:
import pymysql
and then
pymysql.install_as_MySQLdb()
into my app.py file.
I am still really new to all of this. Anybody who's had this could they explain in simple steps please?
There is a workaround to using MySQLdb package for python3. Assuming you have pip3 installed,
sudo pip3 install mysqlclient
should install the necessary packages, you can use
import MySQLdb
as usual afterwards. That's how I've installed it and have been using it since.

Installing mesos egg for python 2.7

I've installed mesos 0.26 successfully on a vm machine.
The installation has been performed on an ubuntu trusty thar system
by following this manual:
https://open.mesosphere.com/getting-started/install/
So far so good. I wanted to write a tiny python framwork.
For this I need to install the eggs via easy_install:
(I've downloaded the eggs accordingly for the trusty thar ubuntu and the 0.26 mesos):
wget http://downloads.mesosphere.io/master/ubuntu/14.04/mesos-0.26.0-py2.7-linux-x86_64.egg
easy_install mesos-0.26.0-py2.7-linux-x86_64.egg
all went fine, however, if I start python in the shell
and type in
import mesos.interface
I get the message: ImportError: No module named interface
As someone suggested, it may be that there is no longer a binding for python, or that they have renamed the API calls. Well, I looked in the version updates here:
http://mesos.apache.org/documentation/latest/upgrades/
Since the transition from 0.19.x to 0.20.x there hasn't been any changes regarding the mesos.interface part, or at least they are not mentioning it here.
To increase the confusion I also get the following error message when I'm typing in python: import mesos.native
There I receive: ImportError: No module named interface.mesos_pb2. To put it into a nutshell: what is going wrong here, and how can it be fixed? And yes, I've googled various web pages, with terms such as "mesos python bindings", mesos +api +python, etc. And yes, I have also consulted the official mesos webpage. There are nice refences for Java and C++ but not for python, or at least they are very well hidden.
Thanks in advance for any hints.
Solved. For what reasons ever:
export PYTHONPATH=${PYTHONPATH}:/usr/lib/python2.7/site-packages/
is required to set the PYTHONPATH. After that step it works like a charm.

Python import of firebase module causes program to loop unexpectedly

So, using the python-firebase pip module, the following code:
from firebase import firebase
print 'test'
Causes the following output:
test
test
test
test
test
Commenting out the import, or importing any other modules, causes test to be printed only once as expected. This is happening on my 2 windows machines at home, with different version of python. My linux boxes at work are not showing this behavior. Extremely weird. Anybody know what could possibly be going on?
The pip install of firebase hasnt been updated and has some bugs in it. Take the latest version from Github you should be fine after using this version.
There is a very good blog post on getting started with this python-firebase here burhan.io check it out :-)
V

ImportError: No module named psycopg2.extensions

I am trying to create an app using GeoDjango and I am completely new to this. After some (failing) attempts at making SpatiaLite work, I decided to try out PostgreSQL. I am following the GeoDjango tutorial, and I am stuck at the python manage.py sqlall world line. When I ran that command (or python manage.py syncdb), I got ImportError: No module named psycopg2.extensions. I looked online and realized I needed to install psycopg2, which I did via MacPorts with sudo port install py27-psycopg2. I reran the program and got the same error. I restarted my computer and ran the program again, and still got the same error. Does anyone know anything else that might have caused this?
Thanks!
PS. If anyone cared to know, I was stuck at the same command while testing out SpatiaLite. I consistently received the 'DatabaseOperations' object has no attribute 'geo_db_type'error. I looked around the internet, didn't find any answer and decided to move on for the time being and maybe try again later.
PSS. I am working on Mac OS X 10.7.5

Accessing a MySQL database from python

I have been trying for the past several hours to find a working method of accessing a mysql database in python. The only thing that I've managed to get to compile and install is pyodbc but the necessary driver is not available for ppc leopard.
I already know about this.
UPDATE:
I've gotten setuptools to install, but now MySQL-python won't build.
UPDATE:
Now I've gotten sqlalchemy to install but while it will show up when called by the command line it won't import when used in my cgi script.
Try SQL Alchemy.
It is awesome.
Install fink. It includes the MySQLdb package.
UPDATE: Now I've gotten sqlalchemy to
install but while it will show up when
called by the command line it won't
import when used in my cgi script.
Can you verify that the Python being invoked from your CGI script is the same as the one you get when you run Python interactively? Check which python and compare it to your webserver CGI settings. That's the only thing I can think of that would cause this - getting it installed in one Python but not the other.
What OS are you on? If you're on something like Ubuntu, sudo apt-get install python-mysqldb is much more reliable than trying to build it yourself.
Also, unless I'm mistaken, SQLAlchemy won't actually help you make the connection itself if you don't have a DB-API2 module (like python-mysqldb) installed - SQLAlchemy sits at the next level up, using the DB-API2 connection and making access to it more Pythonic.

Categories

Resources