1

I extended c++ with python but the exectuable won't run on systems that do not have python installed.

#include "C:\.....python.h"

int main()
{
    Py_Initialize();
    PyRun_SimpleString("print("hello world")\n")
Py_Finalize();
return 0;
}

When I run on a windows system without python installed I receive the following error:

The code execution cannot proceed because python37.dll was not found. Reinstalling the program may fix the problem.

How do I link python37.dll to the executable.

asd plougry
  • 143
  • 1
  • 9
  • 1
    See [static linking vs dynamic linking](https://stackoverflow.com/questions/1993390/static-linking-vs-dynamic-linking). You are linking dynamically; in order to do what you need, you need to statically link the python library (for Windows, this means using `.lib`, not `.dll`). – Amadan Dec 27 '19 at 04:40
  • I've included the python libraries. (python37.lib) in "library directories" under VC++ Directories. – asd plougry Dec 27 '19 at 05:06
  • I'm not a Windows person, but maybe [this](https://stackoverflow.com/questions/45426047/visual-studio-static-linking-for-standalone-exe) can help? VS has a ton of options, and apparently not all `.lib` files are the same. – Amadan Dec 27 '19 at 05:09
  • Your program is missing a part it needs for execution. What actually is your question? The error is clear, the remedy seems obvious but you don't ask a question. – Ulrich Eckhardt Dec 27 '19 at 10:26
  • How do I link python37.dll to the executable. Ulrich Eckhardt – asd plougry Dec 27 '19 at 11:05

2 Answers2

1

Make sure your python folder is in your PATH so it can find the DLL in question.

From the command line:

c:\> set PATH=c:\python\python37;%PATH%
c:\> cd /d c:\path\to\your\exe
c:\path\to\you\exe> myprogram.exe

For more details about how DLLs are found and loaded read the Dynamic-Link Library Search Order page on MSDN

selbie
  • 100,020
  • 15
  • 103
  • 173
0

A DLL is by definition a dynamically linked library, it is a separate module that is looked up and resolved at run time.

If Python is not installed, your application won't run.

You need to either bundle Python with your application or install Python before/during your application installation.

Alternatively you can try linking with Python statically, in which case it will become part of the executable and won't need to be installed separately.

rustyx
  • 80,671
  • 25
  • 200
  • 267