python - SQLAlchemy 和 VirtualEnv 的问题

标签 python sqlalchemy virtualenv

我试图在 OS X 10.5 的 virtualenv 下使用 SQLAlchemy,但似乎无法加载它。

这是我做的

mkvirtualenv --no-site-packages test
easy_install sqlalchemy

我尝试从解释器导入 sqlalchemy,一切正常,但如果我尝试从 python 脚本导入 sqlalchemy,我会收到以下错误:

这是来自 IBM 的教程脚本

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey

Base = declarative_base()
class Filesystem(Base):
    __tablename__ = 'filesystem'

    path = Column(String, primary_key=True)
    name = Column(String)

    def __init__(self, path,name):
        self.path = path
        self.name = name

    def __repr__(self):
        return "<Metadata('%s','%s')>" % (self.path,self.name)

我尝试运行“python test.py”,结果如下:

$ python test.py 
Traceback (most recent call last):
  File "test.py", line 4, in <module>
    from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
  File "/Users/grant/Development/Aircraft/sqlalchemy.py", line 3, in <module>
    from sqlalchemy.ext.declarative import declarative_base
ImportError: No module named ext.declarative

这是我的 sys.path 中的内容

>>> import sys
>>> print '\n'.join(sys.path)

/Users/grant/Development/Python/test/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg
/Users/grant/Development/Python/test/lib/python2.6/site-packages/SQLAlchemy-0.5.4p2-py2.6.egg
/Users/grant/Development/Python/test/lib/python26.zip
/Users/grant/Development/Python/test/lib/python2.6
/Users/grant/Development/Python/test/lib/python2.6/plat-darwin
/Users/grant/Development/Python/test/lib/python2.6/plat-mac
/Users/grant/Development/Python/test/lib/python2.6/plat-mac/lib-scriptpackages
/Users/grant/Development/Python/test/lib/python2.6/lib-tk
/Users/grant/Development/Python/test/lib/python2.6/lib-old
/Users/grant/Development/Python/test/lib/python2.6/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages
/Users/grant/Development/Python/test/lib/python2.6/site-packages

对发生的事情有什么想法吗??

最佳答案

我解决了我自己的问题......我在我工作的同一个文件夹中有另一个名为 sqlalchemy.py 的脚本,它把所有东西都搞砸了。

关于python - SQLAlchemy 和 VirtualEnv 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/999677/

相关文章:

python - 在只读模式下使用 OpenPyXL 获取 Excel 工作表的列名

python - sqlalchemy 中 __table_args__ 的目的是什么?

python - 包含字典的 sqlalchemy 映射对象

python - SQLAlchemy插入现有表,模型中未指定的列的默认项值

python - Conda (Python) 虚拟环境不能从 Windows 移植到 Linux

python - 简单的游戏库存

javascript - 将 python 中的嵌套排序循环转换为 javascript

python - 如何在 Python 中使用 virtualenv?

Python 窗口 : correct virtualenv paths

python - autoenv 甚至在子文件夹中执行