python include studio.h,不能在Visual Studio中包含Python.h

(I do find a lot of similar questions, but so far non of these fits me...)

===========Updated error message, images, Command Line===========

I am trying to #include (that's nearly all the code, the main function is almost empty yet) in visual studio, but it keeps reminding me cannot open source file "Python.h", if I run the program, it will raise an error:

fatal error C1083: Cannot open include file: 'Python.h': No such file or directory

. I added the include and library directories in project Property Pages > VC++ Directories, not working, tried to add the path to C/C++ > Additional Include Directories, not working, and I tried to change it to release mode, still not working...

130f2b8714dd6aa151e6956abc9a9325.png

70c296fb230b0f12c0bad53a7b99040e.png

=================Update 2.0================

I add %(AdditionalIncludeDirectories); to C/C++ > Additional Include Directoriesbut seems not work.

Then I did something really stupid: I copied the headers and .dll to the header include folder... Now it doesn't remind me can't find Python.h any longer, I can code:

Py_Initialize();

PyRun_SimpleString("print('Hello Python!')");

Py_Finalize();

but it won't compile... I got a new error message:

'"C:\Amarth\Programing\CPlusPlusLearning\Release\CPlusPlusLearning.exe"' is not recognized as an internal or external command,

operable program or batch file.

And in Output, it's:

1>------ Build started: Project: CPlusPlusLearning, Configuration: Release Win32 ------

1> PartOne.cpp

1>PartOne.cpp(34): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data

1>PartOne.obj : error LNK2001: unresolved external symbol __imp__Py_Finalize

1>PartOne.obj : error LNK2001: unresolved external symbol __imp__Py_Initialize

1>PartOne.obj : error LNK2001: unresolved external symbol __imp__PyRun_SimpleStringFlags

1>C:\Amarth\Computer_Graphics\Programing\CPlusPlusLearning\Release\CPlusPlusLearning.exe : fatal error LNK1120: 3 unresolved externals

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

That seems obvious as the compiler can only find function declaration but can't find the definition... Besides, according to the similar questions I've seen, most people solved the problem after add the include directories. So if I'm really facing a fancy problem, will it be possible to find and copy all the function definitions then make it work in some way ?

==============OTHER MESSAGES===============

I'm using python 3.5, installed by Anaconda. The include and libs folder is under C:\Users\Amarthgul\Anaconda3, which is also added to system vaiable > path. There's also a Python 3.6 in my computer, but normally I only use its Manuals, and yet it haven't cause any trouble in python environment. Command Line:

/GS /GL /W3 /Gy /Zc:wchar_t /I"C:\Users\Amarthgul\Anaconda3\include" /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc140.pdb" /Zc:inline /fp:precise /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /Fp"x64\Release\CPlusPlusLearning.pch"

解决方案

In Visual Studio Community 2015 I changed the "Active solution configuration" in Build \ Configuration Manager from 'Debug' to 'Release. That solved this problem for me.

I got my following example code from: Tutorial Python embedded in C++

#include

#include

#include

int main()

{

CPyInstance pyInstance;

PyRun_SimpleString("print('Hello World from Embedded Python!!!')");

printf("\nPress any key to exit...\n");

if (!_getch()) _getch();

return 0;

}

class CPyInstance

{

public:

CPyInstance()

{

Py_Initialize();

}

~CPyInstance()

{

Py_Finalize();

}

};

class CPyObject

{

private:

PyObject* p;

public:

CPyObject() : p(NULL)

{ }

CPyObject(PyObject* _p) : p(_p)

{ }

~CPyObject()

{

Release();

}

PyObject* getObject()

{

return p;

}

PyObject* setObject(PyObject* _p)

{

return (p = _p);

}

PyObject* AddRef()

{

if (p)

{

Py_INCREF(p);

}

return p;

}

void Release()

{

if (p)

{

Py_DECREF(p);

}

p = NULL;

}

PyObject* operator ->()

{

return p;

}

bool is()

{

return p? true : false;

}

operator PyObject* ()

{

return p;

}

PyObject* operator = (PyObject* pp)

{

p = pp;

return p;

}

operator bool()

{

return p ? true : false;

}

};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值