2014-11-03 89 views
4

我想在我的Django项目中使用postgresql,所以我一直试图安装psycopg2,但是我一直遇到问题。由于我使用的是virtualenv,所以通过macports安装psycopg2并没有帮助。我需要找到一些方法将其作为应用程序安装在我的虚拟环境中。在Max OSX中尝试“pip安装psycopg2”时出现错误代码1 Yosemite

这里是我的错误,当我尝试点子在我的virtualenv安装:

Downloading/unpacking psycopg2 
Downloading psycopg2-2.5.4.tar.gz (682kB): 682kB downloaded 
Running setup.py  (path:/Users/adfelix2/Documents/Hindsait_Work/Projects/nybc_pilot/build/psycopg2/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 

creating pip-egg-info/psycopg2.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 

writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.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'. 

---------------------------------------- 
Cleaning up... 
Command python setup.py egg_info failed with error code 1 in   /Users/user/'privateinfo'/my_virtualenv/build/psycopg2 
Storing debug log for failure in /Users/user/.pip/pip.log 

好像我需要添加一个目录pg_config?然而,我无法在网上找到任何有助于我这样做的事情。如果有人对此有所回应,请按部就班,非常感谢。谢谢。

回答

5

pg_config应位于

/Library/PostgreSQL/9.3/bin/pg_config

(代替你已经安装的Postgres以往版本为9.3)

只是那个目录添加到您的PATH环境变量,你应该能够前进。

+1

谢谢!这工作完美! – 2014-11-05 00:59:16

+0

这是一个耻辱,我不得不添加PostgreSQL来做到这一点,但一旦我确实安装了它,将PIP升级为SUDO,然后将路径添加到/ etc /路径并重新登录,我就可以安装psycopg2。 – 2015-04-22 17:39:30

4

如果您已经安装了Postgres.app,它位于Mac的菜单栏中,那么您必须将您的路径指向应用程序包中的pg_config可执行文件。您可以通过访问导航到可执行文件

/Applications/Postgres.app/Contents/Versions/9.3/bin 

其中您的版本取决于您安装的内容。把它添加到你的.bash_profile的$ PATH变量中,重新加载它,瞧!

4

如果你像这样运行错误,那么你需要安装两个软件包。

sudo apt-get install libpq-dev python-dev 

立即安装psycopg2

pip install psycopg2 
+0

在python 3上,需要'python3-dev'。 – np8 2017-04-22 20:32:57

1

运行这在终端得到的pg_config可执行

which pg_config 

的位置取决于你如何安装Postgres的,你应该得到类似的路径至其中之一

/Library/PostgreSQL/9.3/bin/pg_config 

/usr/local/bin/pg_config 

添加拿着pg_config可执行文件到您的PATH环境变量这样

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

export PATH="/usr/local/bin:$PATH" 

如果命令which pg_config返回任何的目录,那么你应该首先运行安装postgres

brew install postgres 

然后重复上面列出的步骤。

相关问题