我已经使用以下命令安装了psycopg2:
pip install psycopg2
它工作得很好。安装输出中有一些类似的警告信息
In file included from ./psycopg/psycopg.h:33:
./psycopg/config.h:71:13: warning: unused function 'Dprintf' [-Wunused-function]
static void Dprintf(const char *fmt, ...) {}
^
1 warning generated.
但最终它说
Successfully installed psycopg2
当我运行pip list
时,它也会出现。
现在我尝试在Python中导入它,但是出现了错误:
$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named psycopg2
为什么已成功安装的模块无法在Python中导入? (使用Homebrew安装了Python 2.7.5。使用pip安装了psycopg2。)
$ usr/local/bin/python
时,我实际上可以导入psycopg2。但是,当我尝试对.bash_profile
进行您建议的更改时,没有任何更改生效。我使用了$ source .bash_profile
,然后$ python
,但是旧的python仍然出现。如何使brew的python成为终端中的默认python?(另外,当我运行一个python脚本文件,比如从我编写的shell脚本中,如何确保它使用brew的python调用?) - bootsmaatset
,但我本意是要写export
;这样Bash默认就能找到正确的了。我已经编辑了我的答案来修复这个问题,并回答了你的其他问题。 - Daisy Leigh Brenecki