当我直接运行Python interperter时,我没有导入psycopg2
的问题Python 3.5.1 |Anaconda custom (64-bit)| (default, Dec 7 2015, 11:16:01) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> from psycopg2._psycopg import *
>>>
但是如果我在通过cron执行的脚本中运行import psycopg2
,我会收到以下错误。我怎样才能解决这个问题,以便它可以通过cron运行?
import psycopg2, psycopg2.extras
File "/opt/anaconda3/lib/python3.5/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No module named _psycopg
正如您所看到的,我通过Anaconda进行Python 3.5