Installing psycopg2 into virtualenv when PostgreSQL is not installed on development system

前端 未结 14 1081
一向
一向 2020-12-04 09:24

Is it possible to install psycopg2 into a virtualenv when PostgreSQL isn\'t installed on my development system—MacBook Pro with OS X 10.6?

When I run

相关标签:
14条回答
  • 2020-12-04 09:49

    if you have recently updated python or changed default python (let's say from 3.6 to 3.8). The following code

    sudo apt-get install python-dev   OR    sudo apt-get install python3-dev
    

    will be installing/working for the previous python version.

    so if you want this command to work for the recently updated/changed python version try mentioning that specific version like python3.8 in command like

    sudo apt-get install python3.8-dev  
    

    try above with following

    pip install wheel
    export PATH=/path/to/compiled/postgresql/bin:"$PATH"
    sudo apt-get install libpq-dev
    sudo apt-get install python3.x-dev    **Change x with your version, eg python3.8**
    pip install psycopg2-binary
    pip install psycopg2
    
    0 讨论(0)
  • 2020-12-04 09:51

    Using the method you described in your April 12th update, I was able to install PostgreSQL(+1). Note that I originally was running Python 2.7.1 (32bit) and homebrew threw several errors and warnings regarding using a 32bit version of Python. I have since switched the 64/32 bit version of 2.7.1 and it works like a champ.

    Regarding the pyscopg2, I was able to install it into my virtual environment from source by editing setup.cfg. I set pg_config to correct path inside homebrew's Cellar (pg_config=/usr/local/Cellar/postgresql/9.0.4/bin/pg_config). After saving the changes, I ran python setup.py install with zero issues. It's worth noting that I did not set the Mac's default python setting to 32 bit. I used the new 64 bit from start to finish.

    After looking over some of the documentation, I think if I added homebrew's postgresql path to the system path I could have used pip to install it.

    Reference:
    http://favosdream.blogspot.com/2009/09/make-psycopg2-and-readline-work-in-snow.html

    Update 6-8-2011:
    While porting a project written on OS X to Windows 7, I found out that I had to install PostgreSQL on Windows as well. This ended up creating another user on my start up screen and other things that I just didn't like. While doing some digging I found Windows drivers for PostgreSQL here. I have since uninstalled the full PostgreSQL and installed the ODBC drivers which, thus far, work great.

    To address the original question, after doing a bit more digging I think I found the equivalent ODBC for OS X here. I have not had a chance to try them out, but the concept works very well on Windows 7. I will update this when I get a chance to try them out. Until then, I hope this helps.

    0 讨论(0)
  • 2020-12-04 09:51

    I solved this issue by chance with:

    brew install psycopg2

    instead of

    pip install psycopg2

    0 讨论(0)
  • 2020-12-04 09:56
    apt-get install libpq-dev
    

    helped me in debian squeeze too . After that do pip install psycopg2. I faced problem of pg_config not found problem when i was setting up my environment on heroku , now its working fine .

    0 讨论(0)
  • 2020-12-04 09:56

    You need to install the python-dev package in order to make use of python extensions such as psycopg2. I don't know how to install packages in mac but I run the following commands to install a python package on my Ubuntu machine.

    sudo apt-get install python-dev 
    

    Or

    sudo apt-get install python3-dev
    

    if you are using Python3.x.

    Once the installation is finished run the following command within your virtual environment.

    pip install psycopg2
    
    0 讨论(0)
  • 2020-12-04 09:58
    apt-get install libpq-dev
    

    helped me on debian squeeze

    0 讨论(0)
提交回复
热议问题