Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to import ZopeTransactionExtension from command line

I have a pyramid application and it has this line

from zope.sqlalchemy import ZopeTransactionExtension

It works without any issues

But if I try the same with command line I get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named sqlalchemy

and

from zope.sqlalchemy.datamanager import ZopeTransactionExtension
ImportError: No module named sqlalchemy.datamanager

I am not really sure why this is so. The docs have the same line and it seems to work for them at least

like image 456
Ranjith Ramachandra Avatar asked Dec 09 '22 14:12

Ranjith Ramachandra


2 Answers

I recently got the same error in both a pyramid application and the terminal. Reinstalling didn't work in this case. Apparently the zope.sqlalchemy project renamed ZopeTransactionExtension to ZopeTransactionEvents in version 1.2 which was released 2019-10-17.

To make things clearer we renamed the ZopeTransactionExtension class to ZopeTransactionEvents. Existing code using the ‘register’ version stays compatible.

https://pypi.org/project/zope.sqlalchemy/ under Changes 1.2

To fix this, use register when instantiating the DBSession

from zope.sqlalchemy import register

DBSession = scoped_session(sessionmaker(autoflush=False))
register(DBSession)

According to https://github.com/zopefoundation/zope.sqlalchemy/issues/37

like image 172
Joalon Avatar answered Dec 11 '22 05:12

Joalon


This sounds like an issue with mixing pip and easy_install (which setup.py develop uses). They do not cooperate well together when it comes to namespaced packages like zope.*. I suggest recreating your virtualenv.

like image 31
Michael Merickel Avatar answered Dec 11 '22 04:12

Michael Merickel