2014-11-03 115 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 

然後重複上面列出的步驟。

相關問題