Python 在 mac osx 10.9.5 上安装 Psycopg2
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33866695/
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
install Psycopg2 on mac osx 10.9.5
提问by codinginquarantine
I'm trying to install Psycopg2 on my Mac-book. I still get the same error. I found a lot of same questions on Stack Overflow but no answer seems to work. I think it is outdated. I'm using:
我正在尝试在我的 Mac-book 上安装 Psycopg2。我仍然遇到同样的错误。我在 Stack Overflow 上发现了很多相同的问题,但似乎没有答案。我认为它已经过时了。我正在使用:
Mac osx 10.9.5
Python 3.4.3
My error code is:
我的错误代码是:
Running setup.py egg_info for package psycopg2 Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'. Complete output from command python setup.py egg_info: running egg_info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
Command python setup.py egg_info failed with error code 1 in /Users/stevengerrits/build/psycopg2 Storing complete log in /Users/stevengerrits/Library/Logs/pip.log
为包 psycopg2 运行 setup.py egg_info 错误:找不到 pg_config 可执行文件。
请将包含 pg_config 的目录添加到 PATH 或使用以下选项指定完整的可执行路径:
python setup.py build_ext --pg-config /path/to/pg_config build ...
或使用“setup.cfg”中的 pg_config 选项。命令 python setup.py egg_info 的完整输出:运行 egg_info
编写 pip-egg-info/psycopg2.egg-info/PKG-INFO
将顶级名称写入 pip-egg-info/psycopg2.egg-info/top_level.txt
将dependency_links 写入pip-egg-info/psycopg2.egg-info/dependency_links.txt
警告:manifest_maker:找不到标准文件“-c”
错误:找不到 pg_config 可执行文件。
请将包含 pg_config 的目录添加到 PATH
或使用以下选项指定完整的可执行路径:
python setup.py build_ext --pg-config /path/to/pg_config build ...
或使用“setup.cfg”中的 pg_config 选项。
命令 python setup.py egg_info 失败,错误代码 1 in /Users/stevengerrits/build/psycopg2 将完整日志存储在 /Users/stevengerrits/Library/Logs/pip.log
采纳答案by Vaibhav Mishra
You don't seem to have postgres installed, check how to install postgresql in your system, one of the way is
brew install postgresql
(if you use homebrew- recommended)
or download the postgres app from postgresapp.com, pg_config should come with postgres and psycopg2 is trying to find it.
您似乎没有安装 postgres,请检查如何在您的系统中安装 postgresql,其中一种方法是
brew install postgresql
(如果您使用 homebrew-推荐)或从 postgresapp.com 下载 postgres 应用程序,pg_config 应该与 postgres 一起提供,而 psycopg2 是试图找到它。
回答by mnencia
OSX doesn't include PostgreSQL anymore, so you need to install it in some way to build the binary part of psycopg2 module.
OSX 不再包含 PostgreSQL,因此您需要以某种方式安装它以构建 psycopg2 模块的二进制部分。
I've used both brew
and port
. Installing any PostgreSQL version through one of them will enable you to build the module.
我都用过brew
和port
。通过其中之一安装任何 PostgreSQL 版本将使您能够构建模块。
If you install Postgres in other ways, you need to check that the executable pg_config
in in your path.
如果您以其他方式安装 Postgres,则需要检查pg_config
路径中的可执行文件。
You can check for pg_config
presence using the command
您可以pg_config
使用以下命令检查是否存在
which -a pg_config
If you have Postgres installed and the aforementioned command doesn't return anything, you need to manually find the pg_config
executable and put its containing directory in your PATH with:
如果您安装了 Postgres 并且上述命令没有返回任何内容,您需要手动查找pg_config
可执行文件并将其包含的目录放在您的 PATH 中:
export PATH=/path/to/postgresql/bin/:$PATH
Edit:
编辑:
If you already installed it through homebrew, but it is not in your path, you should check if the /usr/local/bin
directory is present in your path and add itif missing
如果您已经通过homebrew安装了它,但它不在您的路径中,您应该检查该/usr/local/bin
目录是否存在于您的路径中,如果缺少则添加它
If the directory is there, you can try to relink postgres with the following command
如果目录在那里,您可以尝试使用以下命令重新链接 postgres
brew unlink postgresql && brew link postgresql
回答by Jones
To install psycopg2
you need have installed server before( I have installed PostgresApp)
安装psycopg2
之前需要安装服务器(我已经安装了PostgresApp)
Run manually command including the path of pg_config
program in PATH
env variable, in my case:
手动运行命令,包括env 变量中的pg_config
程序路径PATH
,在我的情况下:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin/
and then run
然后运行
pip3 install psycopg2
EDIT:
编辑:
Check directory of pg_config
:
检查目录pg_config
:
which pg_config
回答by danius
If you use Docker and you do not want to install postgresql
in you host system,
you can try to use package psycopg2-binary
and use postgresql
in container.
如果您使用 Docker 并且不想安装postgresql
在您的主机系统中,您可以尝试使用 packagepsycopg2-binary
并postgresql
在容器中使用。
回答by Claudio J. Cáceres
I was fighting with this issue for a complete day. Then I ran a script that I found in Pillow library Issues and solve the problem. Check it out https://github.com/python-pillow/Pillow/issues/3438#issuecomment-435169249
我一整天都在与这个问题作斗争。然后我运行了一个在 Pillow library Issues 中找到的脚本并解决了问题。检查一下 https://github.com/python-pillow/Pillow/issues/3438#issuecomment-435169249
回答by Laban funky monky
I ran pip install psycopg2-binary
and it worked like charm
我跑了pip install psycopg2-binary
它就像魅力一样
回答by Dipnarayan Roy
$ find / -name pg_config 2>/dev/null
$ find / -name pg_config 2>/dev/null
/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
$ export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/
$ export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin/
$ pip install psycopg2
$ pip 安装 psycopg2
回答by HassanSh__3571619
On my MAC, this did the trick:
在我的 MAC 上,这成功了:
pip install psycopg2-binary