是否有一些魔术技巧可以使pipenv安装psycopg2

我的Pipfile看起来像这样:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "==2.1.3"
psycopg2 = "*"

[dev-packages]

[requires]
python_version = "3.6"


我尝试添加并删除pyscopg2-binary的安装,但是没有区别。我在运行OSX 10.14.4的Mac上。

这是运行pipenv install后得到的输出:

An error occurred while installing psycopg2==2.8.3 --hash=sha256:128d0fa910ada0157bba1cb74a9c5f92bb8a1dca77cf91a31eb274d1f889e001 --hash=sha256:227fd46cf9b7255f07687e5bde454d7d67ae39ca77e170097cdef8ebfc30c323 --hash=sha256:2315e7f104681d498ccf6fd70b0dba5bce65d60ac92171492bfe228e21dcc242 --hash=sha256:4b5417dcd2999db0f5a891d54717cfaee33acc64f4772c4bc574d4ff95ed9d80 --hash=sha256:640113ddc943522aaf71294e3f2d24013b0edd659b7820621492c9ebd3a2fb0b --hash=sha256:897a6e838319b4bf648a574afb6cabcb17d0488f8c7195100d48d872419f4457 --hash=sha256:8dceca81409898c870e011c71179454962dec152a1a6b86a347f4be74b16d864 --hash=sha256:b1b8e41da09a0c3ef0b3d4bb72da0dde2abebe583c1e8462973233fd5ad0235f --hash=sha256:cb407fccc12fc29dc331f2b934913405fa49b9b75af4f3a72d0f50f57ad2ca23 --hash=sha256:d3a27550a8185e53b244ad7e79e307594b92fede8617d80200a8cce1fba2c60f --hash=sha256:f0e6b697a975d9d3ccd04135316c947dd82d841067c7800ccf622a8717e98df1! Will try again.
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 7/7 — 00:00:45
Installing initially failed dependencies…
[pipenv.exceptions.InstallError]:   File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 1874, in do_install
[pipenv.exceptions.InstallError]:       keep_outdated=keep_outdated
[pipenv.exceptions.InstallError]:   File "/usr/local/Cellar/pipenv/

............
...........

6m-darwin.so', '    ld: library not found for -lssl', '    clang: error: linker command failed with exit code 1 (use -v to see invocation)', "    error: command 'gcc' failed with exit status 1", '    ----------------------------------------', 'ERROR: Command "/Users/mdd/.local/share/virtualenvs/justfacts-2tIl3QYb/bin/python3 -u -c \'import setuptools, tokenize;__file__=\'"\'"\'/private/var/folders/jz/s0hyvf2n5yd8glg82gphcn9h0000gp/T/pip-install-f6uqfqa9/psycopg2/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' install --record /private/var/folders/jz/s0hyvf2n5yd8glg82gphcn9h0000gp/T/pip-record-k9xlsee0/install-record.txt --single-version-externally-managed --compile --install-headers /Users/mdd/.local/share/virtualenvs/justfacts-2tIl3QYb/bin/../include/site/python3.6/psycopg2" failed with error code 1 in /private/var/folders/jz/s0hyvf2n5yd8glg82gphcn9h0000gp/T/pip-install-f6uqfqa9/psycopg2/']


我尝试了推荐的命令,例如pipenv clean,甚至在新目录中从头开始尝试了所有操作,没有Pipfile,但是没有运气。当我尝试直接通过pipenv install pyscopg2安装psycopg2时,结果相同。

最佳答案

扩展heemayl的评论,我最终需要运行:

brew unlink openssl && brew link openssl --force


然后设置一堆环境变量:

echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"


然后删除Pipfile.lock并再次重新安装所有内容,但首先跳过通过pipenv install --skip-lock创建锁文件,然后使用pipenv lock重新创建锁文件。

关于python - pipenv始终无法安装psycopg2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56796426/

10-14 14:52