I want to use the py-postgresql driver with SQLAlchemy. However, I get the following ImportError. I am using Python 2.7.
Traceback (most recent call last):
File "/home/ed/projects/wiki/main.py", line 3, in <module>
from database import db_session as db
File "/home/ed/projects/wiki/database.py", line 5, in <module>
engine = create_engine('postgresql+pypostgresql://ed:noles98#127.0.0.1:5432/wiki', convert_unicode=True)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/__init__.py", line 386, in create_engine
return strategy.create(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py", line 75, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/usr/lib/python2.7/dist-packages/sqlalchemy/dialects/postgresql/pypostgresql.py", line 65, in dbapi
from postgresql.driver import dbapi20
ImportError: No module named postgresql.driver
Related
I'm working on windows with python 3.7.2 and using uszipcode library and import SearchEngine for getting a list of zip codes which start with the argument of the function.
I'm getting the following errors:
Traceback (most recent call last):
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 338, in dbapi
from pysqlite2 import dbapi2 as sqlite
ModuleNotFoundError: No module named 'pysqlite2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/tutorial/tutorial/Zillow/zillow_runfile.py", line 38, in <module>
st = zl.zipcodes_list(st_items=["100", "770"])
File "C:\Users\user\PycharmProjects\tutorial\tutorial\Zillow\zillow_functions.py", line 32, in zipcodes_list
search = SearchEngine()
File "C:\Users\user\Anaconda3\lib\site-packages\uszipcode\search.py", line 82, in __init__
engine = connect_to_simple_zipcode_db()
File "C:\Users\user\Anaconda3\lib\site-packages\uszipcode\db.py", line 49, in connect_to_simple_zipcode_db
return engine_creator.create_sqlite(path=simple_db_file_path.abspath)
File "C:\Users\user\Anaconda3\lib\site-packages\uszipcode\pkg\sqlalchemy_mate\engine_creator.py", line 51, in create_sqlite
return create_engine(_create_sqlite(path), **kwargs)
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\engine\__init__.py", line 423, in create_engine
return strategy.create(*args, **kwargs)
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\engine\strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 343, in dbapi
raise e
File "C:\Users\user\Anaconda3\lib\site-packages\sqlalchemy\dialects\sqlite\pysqlite.py", line 341, in dbapi
from sqlite3 import dbapi2 as sqlite # try 2.5+ stdlib name.
File "C:\Users\user\Anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\Users\user\Anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: entry module not found.
I've tried to install different libraries according to recommendations I found online:
pip install sqlite-devel
pip install sqlite3tools
pip install libsqlite3-dev
for each of the above I got the following error:
Could not find a version that satisfies the requirement "sqlite-devel <from versions: >
No matching distribution found for "sqlite-devel"
def zipcodes_list(st_items):
search = SearchEngine()
# If st_items is a single zipcode string.
if isinstance(st_items, str):
zc_objects = search.by_prefix(st_items)
# If st_items is a list of zipcode strings.
elif isinstance(st_items, list):
zc_objects = [n for i in st_items for n in search.by_prefix(str(i))]
else:
raise ValueError("arg 'st_items' must be of type str or list")
output = [str(i).split(" ", 1)[1].split(">")[0] for i in zc_objects]
return output
I'm trying to mock the MySQLdb lib from my project but I don't really understood how to do it:
Here's my test code:
import unittest
from mock import MagicMock
from core.distrib.main.CentralDistDraw import CentralDistDraw
from connector.mysql import MySQL
class CentralDistDraw(unittest.TestCase):
def test_hello(self):
draw = CentralDistDraw()
msql = MySQL()
msql.getConnection = MagicMock()
Here's my class:
from datetime import datetime
import logging
from core.distrib.config.PromoConstants import PromoConstants
from dateutil.parser import parse
from google.appengine.api import memcache
from connector.mysql import MySQL
from core.distrib.ndb.userpromo import UserPromo
from core.distrib.ndb.drawinfo import DrawInfo
import traceback
class CentralDistDraw(object):
def getNextNumber(self, idUser, amountDefault=1, amountSpecial=1):
numbersDelivered = []
# DB CONTROLL....
db = MySQL().getConnection()
db.autocommit(False)
currentUser = None
Error thrown:
ERROR: Failure: ImportError (/home/dyego/Documents/code-stuff/mod/pdbcontest2/src/lib/_mysql.so: invalid ELF header)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/nose-1.3.7-py2.7.egg/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
File "/usr/local/lib/python2.7/dist-packages/nose-1.3.7-py2.7.egg/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/local/lib/python2.7/dist-packages/nose-1.3.7-py2.7.egg/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/home/dyego/Documents/code-stuff/mod/pdbcontest2/src/tests/core/test_central_dist_draw.py", line 4, in <module>
from core.distrib.main.CentralDistDraw import CentralDistDraw
File "/home/dyego/Documents/code-stuff/mod/pdbcontest2/src/core/distrib/main/CentralDistDraw.py", line 11, in <module>
from connector.mysql import MySQL
File "/home/dyego/Documents/code-stuff/mod/pdbcontest2/src/connector/mysql.py", line 8, in <module>
import MySQLdb
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: /home/dyego/Documents/code-stuff/mod/pdbcontest2/src/lib/_mysql.so: invalid ELF header
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
Anyone knows the correct way to go when comes to testing third party libraries?
Thanks!
Traceback (most recent call last):
File "main.py", line 4, in <module>
from bot import bot
File "/root/musicbot/bot.py", line 7, in <module>
from database import db, text_search
File "/root/musicbot/database.py", line 2, in <module>
import pymongo
File "/usr/local/lib/python3.5/site-packages/pymongo/__init__.py", line 92, in <module>
from pymongo.connection import Connection
File "/usr/local/lib/python3.5/site-packages/pymongo/connection.py", line 39, in <module>
from pymongo.mongo_client import MongoClient
File "/usr/local/lib/python3.5/site-packages/pymongo/mongo_client.py", line 46, in <module>
from pymongo import (auth,
File "/usr/local/lib/python3.5/site-packages/pymongo/pool.py", line 22, in <module>
from pymongo import thread_util
File "/usr/local/lib/python3.5/site-packages/pymongo/thread_util.py", line 31, in <module>
from gevent.lock import BoundedSemaphore as GeventBoundedSemaphore
File "/usr/local/lib/python3.5/site-packages/gevent/__init__.py", line 36, in <module>
from gevent.hub import get_hub, iwait, wait
File "/usr/local/lib/python3.5/site-packages/gevent/hub.py", line 282
except Exception, ex:
^
SyntaxError: invalid syntax
You are using a Python package which is for Python 2.x and uses old Exception syntax (gevent.hub).
You need to upgrade the violating module to Python 3.x compatible version.
If this is not possible then you need to deploy your application on Python 2.x.
I've tried to make my own server to new sync service in FireFox.
I used the following tutorial: https://docs.services.mozilla.com/howtos/run-sync-1.5.html .
When I wanted to check it by using make test I got the following error:
Traceback (most recent call last):
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/nose/loader.py", line 403, in loadTestsFromName
module = resolve_name(addr.module)
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/nose/util.py", line 311, in resolve_name
module = __import__('.'.join(parts_copy))
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/syncstorage/__init__.py", line 5, in <module>
import mozsvc.config
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/mozsvc/config.py", line 10, in <module>
from konfig import Config, SettingsDict
File "/home/jj/syncserver/local/local/lib/python2.7/site-packages/konfig/__init__.py", line 11, in <module>
from configparser import ConfigParser, ExtendedInterpolation
ImportError: cannot import name ExtendedInterpolation
What's happened?
configparser.ExtendedInterpolation does not exist in Python 2.
You need to use Python 3.
I've installed Python 2.7.2 on my Windows XP computer.
I recently installed SQLAlchemy 0.7.1 using 'python setup.py install'. During the installation, I got the following error messages:
byte-compiling C:\Python27\Lib\site-packages\sqlalchemy\sql\visitors.py to visitors.pyc
SyntaxError: ('invalid syntax', ('C:\\Python27\\Lib\\site-packages\\sqlalchemy\\sql\\visitors.py', 66, 34, 'class Visitable(object, metaclass=VisitableType):\n'))
When I try to import sqlalchemy, I get the following stack trace:
>>> import sqlalchemy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\sqlalchemy\__init__.py", line 12, in <module>
from sqlalchemy.sql import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\__init__.py", line 7, in <module>
from sqlalchemy.sql.expression import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\expression.py", line 32, in <module>
from sqlalchemy import util, exc
File "C:\Python27\lib\site-packages\sqlalchemy\util\__init__.py", line 7, in <module>
from .compat import callable, cmp, reduce, defaultdict, py25_dict, \
File "C:\Python27\lib\site-packages\sqlalchemy\util\compat.py", line 93, in <module>
callable = __builtin__.callable
NameError: name '__builtin__' is not defined
Other scripts work fine and all the functions in __builtin__ seem to be available.
I can't find any examples of similar problems on Google or in the SQLAlchemy documentation.
What's wrong?
UPDATE:
Uncommenting import __builtin__ in compat.py removed the first problem. Now I seem to have problems with visitors.py:
>>> import sqlalchemy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\sqlalchemy\__init__.py", line 12, in <module>
from sqlalchemy.sql import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\__init__.py", line 7, in <module>
from sqlalchemy.sql.expression import (
File "C:\Python27\lib\site-packages\sqlalchemy\sql\expression.py", line 35, in <module>
from sqlalchemy.sql.visitors import Visitable, cloned_traverse
File "C:\Python27\lib\site-packages\sqlalchemy\sql\visitors.py", line 66
class Visitable(object, metaclass=VisitableType):
^
SyntaxError: invalid syntax
Problem partially solved: everything started working when I rolled back to SQLAlchemy 0.6.8. An issue with 0.7.1 + Windows/2.6?