簡體   English   中英

ImportError:沒有名為Analonda的SQLAlchemy模塊

[英]ImportError: No module named SQLAlchemy with Anaconda

我有一個python腳本,可以在我運行過的所有其他遠程服務器上運行,但是由於某種原因,在安裝了Anaconda的特定遠程服務器上,我收到了SQLAlchemy的ImportError。 我正在連接到MySQL數據庫。

#!/usr/bin/python
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker, mapper
import sys
dev_engine = create_engine('mysql://...')
prod_engine  = create_engine('mysql://...')

def transactions(exchange, filepath):
    dev_connect = dev_engine.connect()
    prod_connect = prod_engine.connect()

    get_dev_instrument = "select * from " + exchange + "_instrument;"
    instruments = dev_engine.execute(get_dev_instrument)
    instruments_list = [r for r in instruments]
    get_prod_instrument = "select * from " + exchange + "_instrument;"
    instruments_after = prod_engine.execute(get_prod_instrument)
    instruments_after_list = [r2 for r2 in instruments_after]

    ...

嘗試運行它時出現以下錯誤。

  File "/home/local/filepath/general.py", line 2, in <module>
    from sqlalchemy import *
  ImportError: No module named sqlalchemy

但是,如果我運行python shell,則可以導入sqlalchemy

my.username@remote-server:~$ python
Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Dec  6 2015, 18:08:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> from sqlalchemy import *
>>>

怎么了?

編輯:如果我從其目錄中調用我的腳本,它工作得很好。 由於要從Crontab運行腳本,因此我使用完整的文件路徑調用腳本。

my.username@remote-server:~$ python general.py arg1 arg2
formed maps
my.username@remote-server:~$

my.username@remote-server:~$: /usr/bin/python /home/local/TMG/filepath/general.py arg1 arg2


Traceback (most recent call last):
  File "/home/local/TMG/filepath/general.py", line 2, in <module>
    from sqlalchemy import *
ImportError: No module named sqlalchemy

嘗試添加:

import sys
sys.path.append("/home/local/TMG/filepath")

在腳本的開頭。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM