无法在Mac OS上安装Psycopg2

时间:2019-08-22 23:50:10

标签: python macos

我正在将python3.7.2pip 19.2.2用于python应用程序。问题是我无法在MacOS上安装依赖项psycopg2 2.8.3

以下是我在运行pip install psycopg2时遇到的错误:

ld: library not found for -lssl
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  error: command 'clang' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for psycopg2

似乎未安装ssl,所以我尝试安装pip install sssl,但出现此错误:

ERROR: Command errored out with exit status 1:
     command: /Users/joey/.pyenv/versions/3.7.2/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9c/fcm6pxnj39b1t777zpcfpbdh0000gn/T/pip-install-2ldzdiz0/ssl/setup.py'"'"'; __file__='"'"'/private/var/folders/9c/fcm6pxnj39b1t777zpcfpbdh0000gn/T/pip-install-2ldzdiz0/ssl/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /private/var/folders/9c/fcm6pxnj39b1t777zpcfpbdh0000gn/T/pip-install-2ldzdiz0/ssl/
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/9c/fcm6pxnj39b1t777zpcfpbdh0000gn/T/pip-install-2ldzdiz0/ssl/setup.py", line 33
        print 'looking for', f
                          ^
    SyntaxError: Missing parentheses in call to 'print'. Did you mean print('looking for', f)?
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

我不明白为什么它失败了。是因为版本错误还是与MacOS有关?

我已经尝试了本文中提到的方法:How to install psycopg2 with "pip" on Python?。我在Mac上安装了postgressql,并在PATH环境中添加了/usr/local/Cellar/postgresql/11.5/bin/。但这无济于事。

2 个答案:

答案 0 :(得分:3)

我认为该主题可能对您有帮助error installing psycopg2, library not found for -lssl

clang是osx上默认的c编译器,对于某些python库的正确构建是必需的。 ssl错误实际上是clang链接器抱怨没有可用的ssl库。以上线程可以解决您的问题。

答案 1 :(得分:1)

我遇到了同样的问题,查看了Nate发布的主题,但在这里找到了我的解决方案:How to update Xcode from command line,由Roy Huang发布,他引用了https://forums.developer.apple.com/thread/104296

事实证明,Mojave和/或Xcode 10没有创建psycopg2需要安装的/ usr / include目录。