简体   繁体   中英

Can't install psycopg2 on Windows to use pgloader

I need to upload content of csv file to PostgreSQL . Content isn't perfect and contains mistakes, so I can't just use COPY command, I need to skip broken lines.

So I decided to use pgloader-2.3.2

I have Win8 x64 , Python 2.7.6 x64 , pip 1.5.6 .

Pgloader requires psycopg2 which I installed like described here :

pip install git+https://github.com/nwcell/psycopg2-windows.git@win64-py27#egg=psycopg2

Now I see it in the list:

C:\dev\tools\pgloader-2.3.2>pip list
pip (1.5.6)
psycopg2 (2.5.2)
setuptools (3.6)

But my Python doesn't see it:

>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named psycopg2
>>> 
>>> import sys
>>> print sys.path
['', 'C:\\Windows\\SYSTEM32\\python27.zip', 'C:\\dev\\tools\\Python27\\DLLs', 'C:\\dev\\tools\\Python27\\lib', 'C:\\dev\\tools\\Python27\\lib\\plat-win', 'C:\\dev\\tools\\Python27\\lib\\lib-tk', 'C:\\dev\\tools\\Python27', 'C:\\dev\\tools\\Python27\\lib\\site-packages']

I went to C:\\dev\\tools\\Python27\\Lib\\site-packages\\ directory and found there only psycopg2-2.5.2-py2.7.egg-info directory (there are no psycopg2 or something similar).

How to solve this issue? I'm already spent about a day to solve a bunch of issues and now this one... It's really frustrating, that such primitive task requires so much efforts.

I've tried installing psycopg2 on Windows using the GitHub repo , but had a similar issue because I've chosen the wrong version (32 bits instead of 64 bits). PIP told me that psycopg2 was installed successfully, but trying to run I've received the same message:

ImportError: No module named psycopg2

Unistalled and tried again, with the correct version, and I got the warning:

pip can't proceed with requirement 'psycopg2 from git+ https://github.com/nwcell/psycopg2-windows.git@win32-py34 ' due to a pre-existing build directory. location: C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2\\pip_build_Administrator\\psycopg2 This is likely due to a previous installation that failed. pip is being responsible and not assuming it can delete this. Please delete it and try again.

After cleaning the folder C:\\Users\\my_username\\AppData\\Local\\Temp\\2\\pip_build_my_username and trying again, I've managed to install it correctly.


As pointed in comments, another way would be installing the binaries using: http://www.stickpeople.com/projects/python/win-psycopg/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM