Unable to install pgvector extension for PostgreSQL [Windows]

4.9k Views Asked by At

I am trying to use PostgreSQL as a vector database. And for the same I installed PostgreSQL to my windows system using the instructions provided here.

To install pgvector, I followed the instructions given in this page.

I am trying to complete this setup in a remote machine with Windows Server 2016 OS. PostgreSQL version: 15.3

I was unable to successfully install the pgvector extension. Upon running the nmake /F Makefile.win command, I get the following error:

fatal error C1083: Cannot open include file ‘crtdefs.h’: No such file or directory

Error upon running nmake /F Makefile.win

I tried installing using conda as well. command: conda install -c conda-forge pgvector The error obtained when creating vector extension after installation using conda is as follows:

Create extension error

EDIT 1: Updating the post based on the following question.

Where is the file crtdefs.h on your system? (There could be several of these.) What is the value of the INCLUDE environment variable when cl.exe is called?

crtdefs.h file location: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.36.32532\include

Earlier I didn't have the INCLUDE env variable added. Now, I added the INCLUDE and LIB environment variables based on certain similar errors (cannot open include/lib file). I had to respectively add include and lib paths from Microsoft Visual studio and Windows Kits. Now upon running the nmake /F Makefile.win command, I get the following error.

fatal error LNK1104: cannot open file 'vector.dll'

Error: Cannot open file 'vector.dll'

vector.dll file is not present in the cloned pgvector folder.

Any help with regards to completing installation using nmake or resolve the error while creating the vector extension will be greatly appreciated. Thanks!

4

There are 4 best solutions below

0
On

I have experiencing the same issue when I try to install the vector extension in windows locally and finally get this resolved.

The main reason for this issue is the build C++ environment like all the includes are not setup correct due to local computer did not install Visual Studio (C# dotnet developement) only usually installed the VSCode not the dotnet C#, so it is missing a lot of setup.

To fix this you will need to download the build tools from here: "Build Tools for Visual Studio 2022" https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022

The pgvector repo tell you to setup local env via

Call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"

But in some case the installed path could be:

Call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"

Once run that successful it will remove all the issue of the missing build include files issue

make sure you run CMD in admin mode as the final install will need to copied the compiled DLL file to postgresql folder which need admin permission

make sure you set the environment for where your postgresql are installed

set "PGROOT=C:\Program Files\PostgreSQL\15"

cd to where your pgvector source code directory

this to compiled the DLL

nmake /F Makefile.win

this to copied the SQL files and DLL to postgresql

nmake /F Makefile.win install

The main mistake is missing the run of env setup:

Call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"

Please make sure you have vcvars64.bat file in your build tools

Hope this helps

0
On

I am using Windows + vscode+ Anaconda + Postgres + pgvector , installing pgvector on Windows is a very challenging task here are the steps to install pgvector.

  1. First you need to install C/C++ extension for VS Code.

  2. Open a new window in vs code and select get start with c++, see the right side of vs code, and copy the command, run copy command without quotes in cmd (open as administrator) like this:

"winget install Microsoft.VisualStudio.2022.BuildTools --force --override "--wait --passive --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.22000"

  1. Make sure the Developer Command Prompt is installed. Open the Developer Command Prompt for VS by typing 'developer' in the Windows Start menu.

  2. Check your MSVC installation by typing cl into the Developer Command Prompt for VS. You should see a copyright message with the version and basic usage description.

  3. For installing C++ toolset and MSVC you can also check its official site.

  4. To install the pgvector run this command in your git bash.

git clone --branch v0.5.1 https://github.com/pgvector/pgvector.git

  1. Open the command prompt in administrator mode, change the directory to pgvector folder cd pgvector where it is installed, and run this command (Visit its official site for more details.):

call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"

NOTE: The exact path will vary depending on your Visual Studio version and edition

 set "PGROOT=C:\Program Files\PostgreSQL\15"

NOTE: This installation root can be different so make sure you are entering the correct path

nmake /F Makefile.win

nmake /F Makefile.win install
  1. Install pgvector in conda:

conda install -c conda-forge pgvector

  1. Run below command in the db and check the function directory to make sure the extension exist:

CREATE EXTENSION IF NOT EXISTS vector

enter image description here

In Functions, you should see pgvector function. I hope now you can install pgvector in Windows.

0
On

you should install correct win sdk if you see this error. VS2019 + select VS installer:

  • desktop development
    • select win 10 sdk v..16..
0
On

I followed the instruction in their github page and it worked. You just need to open the command prompt as admin.

Note: Replace 15 with your Postgres server version

Windows Support for Windows is currently experimental. Ensure C++ support in Visual Studio is installed, and run:

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat" Note: The exact path will vary depending on your Visual Studio version and edition

Then use nmake to build:

set "PGROOT=C:\Program Files\PostgreSQL\16" git clone --branch v0.5.0 https://github.com/pgvector/pgvector.git cd pgvector nmake /F Makefile.win nmake /F Makefile.win install