[컴][파이썬] virtualenv 에서 psycopg2 설치하기


pip install psycopg2


virtualenv 에서 pip 로 psycopg2 를 설치하려고 한다.

pg_config path 설정

pip 로 psycopg2 를 설치하는데, pg_config 가 필요해서, 이 pg_config 가 있는 곳의 path 를 지정해줘야 한다. PostgreSQL 의 path 에 "(쌍따옴표) 가 없는 것에 주의하자.
(spike) d:\mine\programming\python\spikeroot\spike>set PATH=%PATH%;d:\Program Files (x86)\PostgreSQL\9.3\bin

이렇게 하고 pip install psycopg2 를 하면 아래처럼 UnicodeEncodeError 가 난다. 관련해서 찾아보니 c/c++ library 를 compile 해서 설치하기 위해서는 python-dev 가 필요하다.[참고]

그렇게 하기는 좀 그래서 다른 방법을 찾아봤다.


(spike) d:\mine\programming\python\spikeroot\spike>pip install psycopg2
Collecting psycopg2
  Using cached psycopg2-2.6.1.tar.gz
Building wheels for collected packages: psycopg2
  Running setup.py bdist_wheel for psycopg2
  Complete output from command d:\envs\spike\scripts\python.exe -c "import setuptools;__file__='f:\\temp\\pip-build-tbpqrl\\psycopg2\\setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d f:\temp\tmpn6bpaapip-wheel-:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-2.7
  creating build\lib.win-amd64-2.7\psycopg2
  copying lib\tz.py -> build\lib.win-amd64-2.7\psycopg2
  copying lib\pool.py -> build\lib.win-amd64-2.7\psycopg2
  copying lib\extras.py -> build\lib.win-amd64-2.7\psycopg2
  copying lib\extensions.py -> build\lib.win-amd64-2.7\psycopg2
  copying lib\_range.py -> build\lib.win-amd64-2.7\psycopg2
  copying lib\__init__.py -> build\lib.win-amd64-2.7\psycopg2
  copying lib\psycopg1.py -> build\lib.win-amd64-2.7\psycopg2
  copying lib\_json.py -> build\lib.win-amd64-2.7\psycopg2
  copying lib\errorcodes.py -> build\lib.win-amd64-2.7\psycopg2
  creating build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\dbapi20.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_bug_gc.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_async.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\testconfig.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_quote.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_extras_dictcursor.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_types_basic.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_transaction.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_cancel.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_dates.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_lobject.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\dbapi20_tpc.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_copy.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_types_extras.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_psycopg2_dbapi20.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_module.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\__init__.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_green.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\testutils.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_with.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_cursor.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_connection.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_notify.py -> build\lib.win-amd64-2.7\psycopg2\tests
  copying tests\test_bugX000.py -> build\lib.win-amd64-2.7\psycopg2\tests
  running build_ext
  building 'psycopg2._psycopg' extension
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "f:\temp\pip-build-tbpqrl\psycopg2\setup.py", line 615, in <module>
      ext_modules=ext)
    File "C:\Python27\Lib\distutils\core.py", line 169, in setup
      raise SystemExit, "error: " + str(msg)
  UnicodeEncodeError: 'ascii' codec can't encode character u'\uc740' in position 813: ordinal not in range(128)

  ----------------------------------------
  Failed building wheel for psycopg2
Failed to build psycopg2
Installing collected packages: psycopg2
  Running setup.py install for psycopg2
    Complete output from command d:\envs\spike\scripts\python.exe -c "import setuptools, tokenize;__file__='f:\\temp\\pip-build-tbpqrl\\psycopg2\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record f:\temp\pip-rdmng4-record\install-record.t
xt --single-version-externally-managed --compile --install-headers d:\envs\spike\include\site\python2.7\psycopg2:
    running install
    running build
    running build_py
    running build_ext
    building 'psycopg2._psycopg' extension
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "f:\temp\pip-build-tbpqrl\psycopg2\setup.py", line 615, in <module>
        ext_modules=ext)
      File "C:\Python27\Lib\distutils\core.py", line 169, in setup
        raise SystemExit, "error: " + str(msg)
    UnicodeEncodeError: 'ascii' codec can't encode character u'\uc740' in position 813: ordinal not in range(128)

    ----------------------------------------
Command "d:\envs\spike\scripts\python.exe -c "import setuptools, tokenize;__file__='f:\\temp\\pip-build-tbpqrl\\psycopg2\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record f:\temp\pip-rdmng4-record\install-record.txt --single-version-externally-managed --compile --install-headers d:\envs\spike\include\site\python2.7\psycopg2" failed with error code 1 in f:\temp\pip-build-tbpqrl\psycopg2


easy install


그래서 아래 글을 찾았다.


방법은 easy install 이다. 아래는 python 2.7 64-bit 버전을 설치한 경우이다.
easy_install http://www.stickpeople.com/projects/python/win-psycopg/2.6.1/psycopg2-2.6.1.win-amd64-py2.7-pg9.4.4-release.exe

위의 글에 따르면 virtualenv 에서도 가능하다고 한다. 실제로 해보니 잘 됐다.

(myproject) d:\mine\programming\python\myprojectroot\myproject>easy_install http://www.stick
people.com/projects/python/win-psycopg/2.6.1/psycopg2-2.6.1.win-amd64-py2.7-pg9.4.4-release.exe
Downloading http://www.stickpeople.com/projects/python/win-psycopg/2.6.1/psycopg2-2.6.1.win-amd64-py2.7-pg9.4.4-release.exe
Processing psycopg2-2.6.1.win-amd64-py2.7-pg9.4.4-release.exe
psycopg2.tests.test_module: module references __file__
psycopg2.tests.test_types_basic: module references __file__
creating 'f:\temp\easy_install-mjt4v1\psycopg2-2.6.1-py2.7-win-amd64.egg' and adding 'f:\temp\easy_install-mjt4v1\psycopg2-2.6.1-py2.7-win-amd64.egg.tmp' to it
creating d:\envs\myproject\lib\site-packages\psycopg2-2.6.1-py2.7-win-amd64.egg
Extracting psycopg2-2.6.1-py2.7-win-amd64.egg to d:\envs\myproject\lib\site-packages

Adding psycopg2 2.6.1 to easy-install.pth file

Installed d:\envs\myproject\lib\site-packages\psycopg2-2.6.1-py2.7-win-amd64.egg
Processing dependencies for psycopg2==2.6.1
Finished processing dependencies for psycopg2==2.6.1

(myproject) d:\mine\programming\python\myprojectroot\myproject>










댓글 없음:

댓글 쓰기