gpt4 book ai didi

python - 将 SQLAlchemy 导入我的项目

转载 作者:太空宇宙 更新时间:2023-11-04 03:43:45 26 4
gpt4 key购买 nike

环境:

  • python 2.7.5
  • SQLAlchemy 0.9.6

我做了什么:

出于不同的原因,我想将 SQLAlchemy 源代码包含到我的项目中。主要原因是避免以后为我的用户使用任何虚拟环境。

好的,我的结构看起来像这样:

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

好的,我将 libs 路径添加到系统路径。

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

当我现在尝试从 libs.sqlalchemy.orm 导入时

from libs.sqlalchemy.orm import relationship

我得到一个错误

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'

这是回溯指向的地方

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

实际问题:

我错过了什么/做错了什么?
我已经从 here 下载了 tar.gz并将 lib/sqlalchemy 文件夹复制到我的 lib 路径

最佳答案

只是解压 tar 文件对炼金术不起作用,因为它有需要编译的 native 库,所以你可以

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

这就是“pip install”正在做的事情:

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

关于python - 将 SQLAlchemy 导入我的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24834586/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com