Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import SQLAlchemy into my project

Environment:

  • Python 2.7.5
  • SQLAlchemy 0.9.6

What I've done:

I want to include the SQLAlchemy source into my project for different reasons. The main reason is to avoid any virtual environments for my users later.

Okay my structure looks like this:

$ tree . -L 2
myapp
├── libs
│   ├── ...
│   └── sqlalchemy
├── myapp
│   └── ...
└── MyApp.py

Okay I add the libs path to the system path.

### MyApp.py
# ...
BASE_DIR = os.path.dirname(__file__)
LIBRARY_DIR = os.path.join(BASE_DIR, 'libs')
sys.path.append(LIBRARY_DIR)
# ...

When I now try to import from libs.sqlalchemy.orm

from libs.sqlalchemy.orm import relationship

I get an error

Traceback (most recent call last):
  File "/.../myapp/MyApp.py", line 13, in <module>
    from libs.sqlalchemy.orm import relationship
  File "/.../myapp/libs/sqlalchemy/orm/__init__.py", line 69, in <module>
    from . import strategies as _strategies
  File "/.../myapp/libs/sqlalchemy/orm/strategies.py", line 301, in <module>
    @properties.RelationshipProperty.strategy_for(lazy="noload")
AttributeError: 'module' object has no attribute 'RelationshipProperty'

This is where the traceback points to

### ./libs/sqlalchemy/orm/strategies.py
@log.class_logger
@properties.RelationshipProperty.strategy_for(lazy="noload") # <- here
@properties.RelationshipProperty.strategy_for(lazy=None)
class NoLoader(AbstractRelationshipLoader):
    # ...

Actual question:

What do I have missed / done wrong?
I've downloaded the tar.gz from here and copied the lib/sqlalchemy folder to my lib path

like image 714
boop Avatar asked May 29 '26 00:05

boop


1 Answers

Just unpackig tar file is not going to work for alchemy, because it has native libraries that need to be compiled, so you can

sudo pip install alchemy or
untar your tar.gz and run "python setup.py install"

This is what "pip install" is doing:

Installing collected packages: sqlalchemy
  Running setup.py install for sqlalchemy
    building 'sqlalchemy.cprocessors' extension
    /usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c lib/sqlalchemy/cextension/processors.c -o build/temp.macosx-10.3-fat-2.7/lib/sqlalchemy/cextension/processors.o
    /usr/bin/clang -bundle -undefined dynamic_lookup -arch i386 -g build/temp.macosx-10.3-fat-2.7/lib/sqlalchemy/cextension/processors.o -o build/lib.macosx-10.3-fat-2.7/sqlalchemy/cprocessors.so
    building 'sqlalchemy.cresultproxy' extension
    /usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c lib/sqlalchemy/cextension/resultproxy.c -o build/temp.macosx-10.3-fat-2.7/lib/sqlalchemy/cextension/resultproxy.o
    /usr/bin/clang -bundle -undefined dynamic_lookup -arch i386 -g build/temp.macosx-10.3-fat-2.7/lib/sqlalchemy/cextension/resultproxy.o -o build/lib.macosx-10.3-fat-2.7/sqlalchemy/cresultproxy.so
    building 'sqlalchemy.cutils' extension
    /usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c lib/sqlalchemy/cextension/utils.c -o build/temp.macosx-10.3-fat-2.7/lib/sqlalchemy/cextension/utils.o
    /usr/bin/clang -bundle -undefined dynamic_lookup -arch i386 -g build/temp.macosx-10.3-fat-2.7/lib/sqlalchemy/cextension/utils.o -o build/lib.macosx-10.3-fat-2.7/sqlalchemy/cutils.so
like image 87
Oleg Gryb Avatar answered May 31 '26 14:05

Oleg Gryb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!