简体   繁体   English

OSX上的psycopg2:我也必须安装PostgreSQL吗?

[英]psycopg2 on OSX: do I have to install PostgreSQL too?

I want to access a postgreSQL database that's running on a remote machine, from Python in OS/X. 我想从OS / X中的Python访问在远程计算机上运行的postgreSQL数据库。 Do I have to install postgres on the mac as well? 我也必须在Mac上安装postgres吗? Or will psycopg2 work on its own. 否则psycopg2会自己工作。

Any hints for a good installation guide for psycopg2 for os/x? 有什么提示可以为os / x提供适用于psycopg2的良好安装指南吗?

macports tells me that the psycopg2 package has a dependency on the postgres client and libraries (but not the db server). macports告诉我psycopg2软件包对postgres客户端和库(而不是数据库服务器)具有依赖性。 If you successfully installed psycopg, then you should be good to go. 如果您成功安装了psycopg,则应该一切顺利。

If you haven't installed yet, consider using macports or fink to deal with dependency resolution for you. 如果尚未安装,请考虑使用macports或fink为您处理依赖项解析。 In most cases, this will make things easier (occasionally build problems erupt). 在大多数情况下,这会使事情变得更容易(有时会引发问题)。

psycopg2 requires the PostgreSQL libpq libraries and the pg_config utility, which means you need a decent chunk of PostgreSQL to be installed. psycopg2需要PostgreSQL libpq库和pg_config实用程序,这意味着您需要安装大量的PostgreSQL。 You could install Postgres and psycopg2 via MacPorts, but the version situation is somewhat messy--you may need to install a newer Python as well, particularly if you want to use a recent version of the PostgreSQL libraries. 您可以通过MacPorts安装Postgres和psycopg2,但是版本情况有些混乱-您可能还需要安装更新的Python,特别是如果您要使用最新版本的PostgreSQL库。 Depending on what you want to do, for example if you have some other Python you want to use, it may be easier to grab a more standard PostgreSQL install and just build psycopg2 yourself. 取决于您要执行的操作,例如,如果要使用其他Python,则可能更容易获得更标准的PostgreSQL安装并自行构建psycopg2。 That's pretty easy if you've already got gcc etc. installed, typically the only build issue is making sure it looks in the right place for the libpq include files. 如果您已经安装了gcc等,那将非常容易,通常唯一的构建问题就是确保它在libpq包含文件的正确位置。 See Getting psycopg2 to work on Mac OS X Leopard and Installing psycopg2 on OS X for a few recipes covering the usual build issues you might run into. 请参阅使psycopg2在Mac OS X Leopard 上运行在OS X上安装psycopg2以获得一些涵盖可能遇到的常见构建问题的食谱。

You can install from an OS X PostgreSQL package . 您可以从OS X PostgreSQL软件包安装。 Allow it to change your memory settings and reboot (it's reversible by removing '/etc/sysctl.conf') - the README file (which tells you to do this yourself) is out of date. 允许它更改内存设置并重新启动(通过删除“ /etc/sysctl.conf”是可逆的)-自述文件(告诉您自己执行此操作)已过期。 Then use (or get, if you haven't already and) EasyInstall . 然后使用(或获取,如果尚未使用) EasyInstall

Check where the PostgreSQL installer has put things - mine is here: 检查PostgreSQL安装程序的放置位置-我的在这里:

/Library/PostgreSQL/8.4/

Add this path to your .bash_login or .bash_profile file in your home directory (make one if you don't have it already): 将此路径添加到主目录中的.bash_login.bash_profile文件中(如果还没有,请创建一个):

export PATH="/Library/PostgreSQL/8.4/bin:$PATH"

Then (on an Intel iMac running OS 10.4.11 and Python 2.6) do: 然后(在运行OS 10.4.11和Python 2.6的Intel iMac上)执行以下操作:

sudo easy_install psycopg2

This found psycopg2 2.0.11 and (on my setup) gave the following readout: 发现psycopg2 2.0.11并(在我的设置中)给出了以下读数:

warning: no files found matching '*.html' under directory 'doc'
warning: no files found matching 'MANIFEST'
zip_safe flag not set; analyzing archive contents...
Adding psycopg2 2.0.11 to easy-install.pth file

Installed /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/psycopg2-2.0.11-py2.6-macosx-10.3-i386.egg
Processing dependencies for psycopg2
Finished processing dependencies for psycopg2

So I guess I have no psycopg2 documentation... however, despite the warnings, I could then do: 所以我想我没有psycopg2文档...但是,尽管有警告,我还是可以这样做:

python
>>>import psycopg2
>>>

Success? 成功? Perhaps. 也许。 I haven't tried running anything yet, but getting a successful import was the first goal. 我还没有尝试运行任何东西,但是成功导入是首要目标。 BTW this was for Django. 顺便说一句,这是给Django的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM