26

I installed psycopg2 in virtualenv using easy_install psycopg2. I did not see any errors and looks like installation went fine.. there is an egg file created in the site-packages dir for psycopg2..

but when I run import psycopg2 in the interpreter, I am getting following error.. any clue? How can I fix it.. any other way to install psycopg2 in virtualenv..

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build\bdist.win32\egg\psycopg2\__init__.py", line 69, in <module>
  File "build\bdist.win32\egg\psycopg2\_psycopg.py", line 7, in <module>
  File "build\bdist.win32\egg\psycopg2\_psycopg.py", line 6, in __bootstrap__

Thanks.

StackUnderflow
  • 24,080
  • 14
  • 54
  • 77

4 Answers4

15

Edit: this solution is outdated. Refer to this answer instead.

I had the same problem. Following the suggestion on the download page of the Windows port for getting it working on Zope worked for me under virtualenv (also in the non-virtual install):

  1. Download the executable, rename the .exe extension to .zip
  2. Extract the file contents.
  3. Copy the psycopg2 folder to MyEnv/Lib
  4. Copy the egg to MyEnv/Lib/site-packages
Community
  • 1
  • 1
ropable
  • 1,547
  • 1
  • 19
  • 31
  • 30
    You don't need to do this manually. You can just `easy_install http://www.stickpeople.com/projects/python/win-psycopg/psycopg2-2.4.win32-pyx.x-pg9.0.3-release.exe` Take a look at [this](http://stackoverflow.com/questions/5382801/where-can-i-download-binary-eggs-with-psycopg2-for-windows/5383266#5383266) answer. – Piotr Dobrogost Mar 21 '11 at 23:15
  • Doing this manually is probably a bad idea, as it will make your virtualenv hard to maintain and re-create on other machines. I'd suggest trying to find a different workaround. – slacy Jun 02 '11 at 23:20
  • 1
    Yeah, I'd go with that other solution. It's a better one. – ropable Dec 18 '12 at 12:38
  • 1
    There is a pip package on github (disclaimer, I put it together). Just do: `pip install git+https://github.com/nwcell/psycopg2-windows.git@win32-py25#egg=psycopg2` You can see the full docs at https://github.com/nwcell/psycopg2-windows – InsanelyADHD May 29 '14 at 21:22
5

Have you checked that PostgreSQL's 'bin' directory is on the system path? Check with a quick typing of 'set' and see what you get.

This is the most common cause of import failures of psycopg2 on Windows.

Lee
  • 2,204
  • 13
  • 15
0

I used the command py -m pip install "psycopg2" and it worked for me. pip install psycopg2 didn't work.

This Link helped me.

MD Mushfirat Mohaimin
  • 1,966
  • 3
  • 10
  • 22
James Roy
  • 21
  • 2
-3

There is an alternative to install python packages in your computer i.e, pip. You can download python packages by just executing:-

    pip install psycopg2 

The general format of the command is

    pip install [package-name]

P.S:- To install python packages globally through pip

    sudo pip install [package-name]