繁体   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