python - pipenv 始终无法安装 psycopg2

标签 python python-3.x psycopg2 pipenv

是否有一些魔术可以让 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 锁

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

相关文章:

pandas - 将 Pandas 数据框变成内存中的类似文件的对象?

python - Opencv 在我的笔记本电脑上为我的项目工作,但停止在树莓派上工作

python - 通过解释器查看所有 python 运算符的列表

python - 诅咒 can_change_color() 总是返回 False

python - Pygame 中自上而下的运动/等距运动

Python pandas检查数据框是否不为空

python - PyQT |如果路径有空格,QDesktopServices.openUrl 不起作用

python - 在 python 中用值填充 CSV 文件的列

python - Postgresql python插入,列关系不存在

postgresql - pytest_postgresql 示例引发导入错误 psycopg