简体   繁体   中英

Howto install psycopg2 in virtualenv with mx support?

I have a virtualenv venv where I installed mx-base and psycopg2 with pip:

$ pip freeze | grep "psyco\|mx"
egenix-mx-base==3.2.8
psycopg2==2.6

The basics of psycopg2 works but when using extensions I get exceptions like this:

Traceback (most recent call last):
  File "/my_proj/my_code.py", line 32, in <module>
    register_types()
  File "/my_proj/my_code.py", line 28, in register_types 
    psycopg2.extensions.register_type(psycopg2._psycopg.MXDATETIME)
AttributeError: 'module' object has no attribute 'MXDATETIME'

Or:

ulf@kalla:~(0)(venv)$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> #Use mx.DateTime instead of pythons datetime, for compability reasons.
... psycopg2.extensions.register_type(psycopg2._psycopg.MXDATETIME)
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AttributeError: 'module' object has no attribute 'MXDATETIME'
>>> 

It seems that the installed version of psycopg2 lacks the mx -support.

How could I fix this?

You will probably need to build psycopg2 on your own, download the tar.gz, unzip, and then find the setup.cfg file, modify the mx_include parameter to be /lib/python2.7/site-packages/mx/DateTime/mxDateTime and then

python setup.py build_ext install

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