在Mac OS上安装psycopg2失败

7
我正在使用Python应用程序的python3.7.2pip 19.2.2。问题是我无法在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有关?
我尝试过这篇文章中提到的方法:如何使用"pip"在Python上安装psycopg2?。我在Mac上安装了postgressql并将/usr/local/Cellar/postgresql/11.5/bin/添加到PATH环境变量中。但这没有帮助。

可能是如何在Python上使用“pip”安装psycopg2?的重复问题。 - Michael Cheng
向下滚动以获取适用于macOS的特定答案。 - Michael Cheng
2个回答

13

我认为这个主题可能会有所帮助:安装psycopg2时出错,-lssl未找到库

clang是OSX上的默认C编译器,并且某些Python库需要正确构建。 SSL错误实际上是clang链接器抱怨没有可用的SSL库可供使用。上面的线程应该解决您的问题。


11
是的,这个设置解决了我的问题。export LDFLAGS="-L/usr/local/opt/openssl/lib"表示将OpenSSL库的路径添加到链接器标志中;export CPPFLAGS="-I/usr/local/opt/openssl/include"表示将OpenSSL头文件的路径添加到编译器标志中。 - Joey Yi Zhao

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接