Python “psycopg2 的构建轮失败” - MacOSX 使用 virtualenv 和 pip

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34304833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:47:59  来源:igfitidea点击:

"Failed building wheel for psycopg2" - MacOSX using virtualenv and pip

pythondjangopostgresqlvirtualenvpsycopg2

提问by Taygo0o

I'm attempting to make a website with a few others for the first time, and have run into a weird error when trying to use Django/Python/VirtualEnv. I've found solutions to this problem for other operating systems, such as Ubuntu, but can't find any good solutions for Mac.

我第一次尝试与其他几个人一起创建一个网站,并且在尝试使用 Django/Python/VirtualEnv 时遇到了一个奇怪的错误。我已经为其他操作系统(例如 Ubuntu)找到了解决此问题的方法,但找不到适用于 Mac 的任何好的解决方案。

This is the relevant code being run:

这是正在运行的相关代码:

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt

After running that block, I get the following errors:

运行该块后,我收到以下错误:

AssertionError


Failed building wheel for django-toolbelt Running setup.py bdist_wheel for psycopg2

断言错误


django-toolbelt 的构建轮失败为 psycopg2 运行 setup.py bdist_wheel

...

...

AssertionError


Failed building wheel for psycopg2 Failed to build django-toolbelt psycopg2

断言错误


psycopg2 的构建轮失败 无法构建 django-toolbelt psycopg2

I believe I've installed the "django-toolbelt" and "psycopg2", so I'm not sure why it would be failing.

我相信我已经安装了“django-toolbelt”和“psycopg2”,所以我不确定它为什么会失败。

The only difference I can think of is that I did not use the command

我能想到的唯一区别是我没有使用命令

sudo apt-get install libpq-dev

as was instructed for Ubuntu usage as I believe that installing postgresql with brew took care of the header.

按照 Ubuntu 使用的指示,因为我相信用 brew 安装 postgresql 会处理标题。

Thanks for any help or insight!

感谢您的任何帮助或见解!

回答by Sniper_3B

Is your error message complete? the most encountered reason for failing to install psycopg2 on mac from pip is pg_config is not in path. by the way, using macports or fink to install psycopg2 is more recommended way, so you don't have to worry about pg_config, libpq-dev and python-dev.

您的错误信息是否完整?无法从 pip 在 mac 上安装 psycopg2 的最常见原因是 pg_config 不在路径中。顺便说一下,使用 macports 或 fink 安装 psycopg2 是比较推荐的方式,所以你不必担心 pg_config、libpq-dev 和 python-dev。

plus, are using Python 3.5? then upgrage your wheel to > 0.25.0 using pip.

另外,正在使用 Python 3.5 吗?然后使用 pip 将您的轮子升级到 > 0.25.0。

回答by Nikolaos Dalezios

I had the same problem on Arch linux. I think that it's not an OS dependant problem. Anyway, I fixed this by finding the outdated packages and updating then.

我在 Arch linux 上遇到了同样的问题。我认为这不是操作系统相关的问题。无论如何,我通过查找过时的软件包并更新来解决此问题。

pip uninstall psycopg2
pip list --outdated
pip install --upgrade wheel
pip install --upgrade setuptools
pip install psycopg2

hope this helps...

希望这可以帮助...

回答by Elmer Medez

On OS X, I was able to solve this by simply upgrading wheel before installing psycopg2:

在 OS X 上,我可以通过在安装 psycopg2 之前简单地升级 wheel 来解决这个问题:

pip install --upgrade wheel

回答by hahmed

For Mac OS X users:

对于 Mac OS X 用户:

1. First check your postgresql path by running this command in terminal:

1. 首先通过在终端中运行此命令来检查您的 postgresql 路径:

pg_config

If this fails lookup how to add pg_config to your path.

如果这失败查找如何将 pg_config 添加到您的路径。

2. Next install Xcode Tools by running this command in terminal:

2. 接下来通过在终端中运行此命令来安装 Xcode Tools:

xcode-select --install

If you have both those sorted out now try to install psycopg2 again

如果您现在已经解决了这两个问题,请尝试再次安装 psycopg2

回答by Adam Starrh

For OSX Sierra users, it seems that an xcode update is the solution: Can't install psycopg2 package through pip install... Is this because of Sierra?

对于 OSX Sierra 用户,似乎 xcode 更新是解决方案:无法通过 pip install 安装 psycopg2 包...这是因为 Sierra 吗?

回答by Farzad Farazmand

I had same problem and this appears to be a Mojave Issue, I was able to resolve with:

我有同样的问题,这似乎是一个莫哈韦问题,我能够解决:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

回答by Abhishek Singh

I was also getting same error. Using Python 3.7.3 and pip 19.1.1.

我也遇到了同样的错误。使用 Python 3.7.3 和 pip 19.1.1。

error screen

错误画面

I used following command.

我使用了以下命令。

pip install psycopg2-binary==2.8.3

回答by Utsav Preet

I faced the same issue, but the answers above didn't work for me. So this is what I did in my requirements.txt psycopg2-binary==2.7.6.1and it worked fine

我遇到了同样的问题,但上面的答案对我不起作用。所以这就是我在我的 requirements.txt psycopg2-binary==2.7.6.1 中所做的,它运行良好

回答by codezero11

I tried all the above solutions but they did not work for me. What I did was change the psycopg2 version in my requirements.txt file from psycopg2==2.7.4to psycopg2==2.7.6

我尝试了上述所有解决方案,但它们对我不起作用。我所做的是将我的 requirements.txt 文件中的 psycopg2 版本从psycopg2==2.7.4更改为psycopg2==2.7.6

回答by Romain

For MacOS users

对于 MacOS 用户

After trying all the above methods (which did not work for me on MacOS 10.14), that one worked :

在尝试了上述所有方法(在 MacOS 10.14 上对我不起作用)后,该方法有效:

  • Install openssl with brew install opensslif you don't have it already.
  • add openssl path to LIBRARY_PATH:
  • brew install openssl如果您还没有安装 openssl,请安装它。
  • 将 openssl 路径添加到LIBRARY_PATH
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
  • install psycopg2 with pip pip3 install psycopg2
  • 使用 pip 安装 psycopg2 pip3 install psycopg2