Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top