0
我想在我沒有root權限的計算機上運行python腳本。爲此,我使用Python 2.7創建了一個virtualenv
,然後添加了我需要並行Python和SQLAlchemy的兩個包。當我運行該腳本,我得到這個錯誤:在virtualenv SQLAlchemy錯誤
(virtPython)thaddeus:recipes ab940$ python2.7 matchIngsParallel.py
Starting pp with 8 workers
Reading ingredients into dictionary
Traceback (most recent call last):
File "matchIngsParallel.py", line 65, in <module>
for synonym, parentIng in session.query(IngSyn.synonym, IngSyn.parentIng):
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/orm/query.py", line 2227, in __iter__
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/orm/query.py", line 2242, in _execute_and_instances
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/engine/base.py", line 1449, in execute
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/engine/base.py", line 1584, in _execute_clauseelement
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/engine/base.py", line 1698, in _execute_context
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/engine/base.py", line 1691, in _execute_context
File "build/bdist.macosx-10.6-intel/egg/sqlalchemy/engine/default.py", line 331, in do_execute
sqlalchemy.exc.OperationalError: (OperationalError) no such table: ingSyns u'SELECT "ingSyns".synonym AS "ingSyns_synonym", "ingSyns"."parentIng" AS "ingSyns_parentIng" \nFROM "ingSyns"'()
它好像一切都被正確導入但數據庫沒有被正確訪問。
的腳本如下:
from assignDB import *
from sqlalchemy.orm import sessionmaker
import pp, sys
ppservers =()
job_server = pp.Server(ppservers=ppservers)
print "Starting pp with", job_server.get_ncpus(), "workers"
print "Reading ingredients into dictionary"
ingreds = {}
for synonym, parentIng in session.query(IngSyn.synonym, IngSyn.parentIng):
ingreds[synonym] = parentIng
print "Finished reading ingredients"
(該代碼被縮短,但包括其中發生錯誤的地方)
assignDB
看起來像這樣:
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine, Table
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, backref, sessionmaker
from sqlalchemy.dialects.sqlite import DATETIME, REAL
engine = create_engine('sqlite:///recDB.db')
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
隨後類定義。
我試過這個腳本在其他計算機上(我有root權限,但是),包括其他virtualenvs,它工作正常。我很困惑會發生什麼問題!
是的,我正在訪問一個保管箱文件夾,所以它在所有機器上都是一樣的。我認爲virtualenv調用導入的方式存在一些問題,特別是'assignDB'?如果它在創建引擎時找不到數據庫,它會不會傳遞錯誤? – abroekhof 2012-07-20 13:30:28
如果SQLite驅動程序找不到該文件,它會創建它,因此您不會在那裏看到錯誤。 ''sqlite:/// recDB.db''是一個相對於你當前工作目錄的路徑,我想你在啓動你的python外殼之後,進入dropbox文件夾?你的'assignDB'導入成功了,否則你的腳本的第一行會出現'ImportError'。是什麼讓你認爲這是一個進口問題? – Simon 2012-07-20 16:16:37