20

I am trying to #include <Python.h> in my C++ code and when I go to compile my code I get this error:

fatal error LNK1104: cannot open file 'python33_d.lib'

I have tried to find python33_d.lib on my computer to include in my linker dependencies, but I cannot find it. I have been able to find python33.lib.

Where can I find the python33_d.lib, or how can I resolve this issue?

7 Answers 7

36

Simple solution from the python bug tracker:

#ifdef _DEBUG
  #undef _DEBUG
  #include <python.h>
  #define _DEBUG
#else
  #include <python.h>
#endif
25

In the event that you need a debug version (as I do for work), it is possible to build the library yourself:

  1. Download the source tarball from http://www.python.org/download
  2. Extract the tarball (7zip will do the trick) and go into the resulting directory (should be something like Python-3.3.2).
  3. From the Python directory, go to the PCBuild folder. There are two important files here: readme.txt, which contains the instructions for building Python in Windows (even if it uses the UNIX line feed style...), and pcbuild.sln, which is the Visual Studio solution that builds Python.
  4. Open pcbuild.sln in Visual Studio. (I am assuming you are using Visual Studio 10; readme.txt contains specific instructions for older versions of Visual Studio.)
  5. Make sure Visual Studio is set to the "debug" configuration, and then build the solution for your appropriate architecture (x64 or Win32). You may get a few failed subprojects, but not all of them are necessary to build python33_d; by my count, 8 builds failed and I got a working .lib file anyway.
  6. You will find python33_d.lib and python33_d.dll in either the PCBuild folder (if building Win32) or the amd64 subfolder (if building x64).
2
  • I started down this path then after running the command build.bat -d I got an error saying I needed a specific version of Visual Studio (v2015) installed, which I didn't want to do. So, I went with @aquirdturtle solution, which allowed me to modify my current installation by adding the debug library. Now, I no longer get the error stated by the OP. Jun 12, 2020 at 15:59
  • How do you download the source tarball??
    – Johan hvn
    Nov 16, 2022 at 15:46
20

*_d.lib is used for debug builds. Switch to a release build instead.

4
  • Now when I run it can't find the python33.dll. I add it to my Project, do I need to add a path to python33.dll to my properties? Jun 10, 2013 at 17:17
  • Put that DLL somewhere the loader expects to find it, such as the current directory. Jun 10, 2013 at 17:18
  • Okay so I copy pasted Python33.dll in my current directory and now I am getting a access violation error Unhandled exception at 0x000000001E17D5CD (python33.dll) in PythTest.exe: 0xC0000005: Access violation reading location 0x0000000000000008. Jun 10, 2013 at 17:36
  • 1
    This is not correct solution... this is just for avoid current build error.
    – summation
    May 25, 2018 at 12:25
12

If you install python via the installers on python.org, you can tell the installer to include the debugging symbols and binaries such as the pythonXX_d.dll file by selecting "Customize Installation" while installing (I think it's on the second customization page). This may be the easiest solution if you're not very savvy at building the project yourself (like me). Too bad I don't see any way to do this with the anaconda distribution.

3
  • 2
    note that this option is not on the first screen you see after selecting customize (this threw me off for a bit). You have to click the "Next" button and then you will see the option. Sep 15, 2017 at 15:22
  • I do this and get the error: Error LNK1107 invalid or corrupt file: cannot read at 0x358 App C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\python39_d.dll What is wrong?
    – Johan hvn
    Nov 17, 2022 at 18:08
  • No idea. I suggest asking a new question. Nov 18, 2022 at 17:45
10

Open Python installer(.exe) -- Modify -- Next -- Enable checkbox Debug Symbols and Libs

2
  • 3
    This should be the accepted answer and it takes literally 1 minute to reinstall Python including all debug symbols.
    – Riverman
    May 1, 2021 at 13:28
  • 2
    True. This should be accepted as the answer. It works without any tweaking. Feb 3, 2022 at 19:50
0

If you are using Swig to generate python wrappers then you can define the macro SWIG_PYTHON_INTERPRETER_NO_DEBUG. In which case it will not look for python**_d.lib

0

As addition to the answer of @liorda: It might happen that there appears conflicts with other libraries and python. The error C1017: invalid integer constant expression may come up.

For this use @liorda's code and replace

#define _DEBUG

with

#define _DEBUG 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.