9

I am trying to install psycopg2 under Windows (Windows 7, 64 bit). I am using Python 2.7.2 from Python(x,y) and PostgreSQL 9.2.1 .

My first try was using the windows port that is downloadable from http://www.stickpeople.com/projects/python/win-psycopg/ (psycopg2-2.4.5.win-amd64-py2.7-pg9.1.3-release.exe). I get a message then that

Python 2.7 required but was not found in the registry

In the next dialogue it does not allow me to choose any python installations. All other programs and installations find my python happily.

This being failed, I tried to use the source package directly from http://pypi.python.org/pypi/psycopg2 but after trying:

python setup.py install

I am now stuck with the error message:

error: Unable to find vcvarsall.bat

Does anybody have an idea how to solve this?

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
Markus M.
  • 1,182
  • 2
  • 8
  • 17
  • `vcvarsall.bat` is part of Microsoft Visual Studio, it sets up the compilation environment for compiling new programs from source code. You don't want to go there on Windows, compiling on Windows is a major pain; you'll need the PostgreSQL header files for libpq and all sorts of other bleagh. I've developed patches for PostgreSQL and tested them on Windows; it's not something I recommend you do unless you have to. – Craig Ringer Nov 01 '12 at 05:21
  • How did you install Python 2.7? From what distribution/source? The psycopg2 installer appears to expect particular registry keys from a Windows installer. – Craig Ringer Nov 01 '12 at 05:23
  • THanks for the reply. Yes, I was aware that the vcvarsall.bat-issue might be a larger problem than I am willing to tackle. My puthon installation is python(x,y) 2.7.2.3 – Markus M. Nov 01 '12 at 06:10
  • Allow me to rephrase. What website did you download Python from? What is the file name of the installer you used? (There is more than one different Python installer). – Craig Ringer Nov 01 '12 at 07:42
  • I downloaded from http://code.google.com/p/pythonxy/wiki/Downloads. The name of the installer is 'Python(x,y)-2.7.2.3.exe'. – Markus M. Nov 01 '12 at 07:52
  • Interesting. It *claims* to be compatible with all plugins, etc, from the official Python distribution. I'm guessing it didn't count on an installer using the Registry to check where Python was installed. – Craig Ringer Nov 01 '12 at 08:20
  • BTW, if you're using *any* software distribution other than the standard one, or if there is no singles standard one, please *say so in the question*. If you'd said "I'm using Python 2.7.2.3 from Python(x,y)" that would've saved all the back-and-forth. See the edited question for what I mean. The same goes for PostgreSQL: "PostgreSQL 9.2.1 from the EnterpriseDB one-click installer" or "PostgreSQL 9.2.1 from BitNami WAPP", for example. – Craig Ringer Nov 01 '12 at 08:26
  • Thanks for the remark. I was not aware that the different python distributions are different enough to cause trouble when installing other components. – Markus M. Nov 02 '12 at 01:10

2 Answers2

17

You're using a different Python distribution to the one the psycopg2 installer expects, so it cannot find the Python install location.

You can manually install psycopg2 from the binaries you downloaded by following the instructions on the psycopg2 download page for issues installing with Zope, which read:

It has been noted that the the installers for psycopg2 will not find the zope installation of python, stop the installation, and not installing psycopg2. A work around is to extract the files by renaming the extension from *.exe to *.zip and using a zip extractor (such as WinZip/PkZip/7z) to extract the psycopg2 folder and place it at \lib\python. I do not use Zope, so I will not be able to provide support or instructions on how to use it. Let me know if it does not work, though.

The same will apply to the Python(x,y) distribution that you are using. Unzip the psycopg2 installer .exe using 7-zip, then copy the psycopg2 folder and 'psycopg2-2.5.2-py2.7.egg-info' file (so 'psycopg2' will apear on 'pip freeze') into your Python lib\site-packages directory. See installing Python modules.

You should then be able to import psycopg2.

ItayB
  • 10,377
  • 9
  • 50
  • 77
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • Craig, many thanks for your help. This was the solution I have been looking for. – Markus M. Nov 02 '12 at 03:30
  • 1
    Thanks! I think it worth mention that lib\site-packages is located under the specific virtualenv that you are currently workon and that you should copy the 'psycopg2-2.5.2-py2.7.egg-info' as well (from the zip file) - so 'psycopg2' will apear on 'pip freeze' – ItayB Jan 10 '14 at 12:03
  • @ItayB Good thought. Feel free to explain in an edit to the answer if you feel like it. – Craig Ringer Jan 11 '14 at 03:30
2
  1. Choose the appropriate version from this page:

    http://www.stickpeople.com/projects/python/win-psycopg/

  2. Right click and select copy link address

  3. Back at home, use easy_install <<Paste URL Here>>

  4. Freeze your new requirements: pip freeze > requirements.txt

Adam Starrh
  • 6,428
  • 8
  • 50
  • 89
  • 1
    Note: this is only required for older versions of psycopg2. As of version 2.7, it should install just fine via pip. – Adam Starrh Apr 24 '18 at 23:32