How to install psycopg2 on PTVS?

Jul 15 at 10:53 PM
psycopg2 is a PostgreSQL driver for Python. If I try to install it with pip or easy_install it downloads the source code and tries to compile it which fails every time on windows. For that it is the best to use the binaries. However, when I run the MSI and install the driver to the global python interpreter/environment, my PTVS environment doesn't recognize I installed that, because of a virtual environment, off course.

How can I add psycopg2 to my virtual environment in Visual Studio?
Coordinator
Jul 15 at 11:00 PM
Edited Jul 15 at 11:01 PM
At the page for the binaries that you've linked to, there is a section titled "Virtual Environment Installation Notes" - follow the instructions (Method 1) there. Note that you can use PTVS UI for package installation in the same manner as command line - just select easy_install as installation method, and use a full path to the .exe as package name; we will pass it along to easy_install as is.
Marked as answer by boskicthebrain on 7/15/2014 at 4:51 PM
Jul 15 at 11:17 PM
Well, I found a workaround, but I would still like to solve this properly.

The workaround would be to install everything I need in the virtual environment, and in the end to edit the pyvenv.cfg so that the line:
include-system-site-packages = false
is changed to:
include-system-site-packages = true
This way all global packages also fit into our local environment. Not pretty, but works...
Coordinator
Jul 15 at 11:35 PM
I'm not sure I follow...

If you have include-system-site-packages = false (which is the default) in your pyvenv.cfg, then you're requesting isolation of your environment from the global one - so any globally installed modules should not be visible in your environment (and hence PTVS behavior is expected). In this case, if you want the package, then you should install it into the environment.

OTOH, if you do want to see global packages, then you should just set include-system-site-packages = true. PTVS should respect that setting.

Also note that we respect the presence of the no-global-site-packages.txt file (this is regardless of pyvenv.cfg setting)
Jul 15 at 11:52 PM
I tried the easy_install approach and it worked! (although it failed once, and then succeeded). Thanks!