From a related post, one installed package matplotlib-cpp through microsoft /
vcpkg . However, when running a simple example,
#include "matplotlibcpp.h"
namespace plt = matplotlibcpp;
int main() {
plt::plot({1,3,2,4});
plt::show();
}
an error returned stating that
Error C1083 Cannot open include file: 'Python.h': No such file or directory Examples
..\vcpkg\installed\x64-windows\include\matplotlibcpp.h 5
I have tried the methods in:
can't include Python.h in visual studio
psycopg: Python.h: No such file or directory and Cygwin gcc issue - cannot find Python.h (which didn't apply since vs managed python environment itself, and there wasn't python-dev option)
A very similiar post C++: matplotlibcpp.h and Python.h linker error also indicated the same issue in Ubuntu environment.
In matplotlibcpp.h file, it mentioned that
// Python headers must be included before any system headers, since
// they define _POSIX_C_SOURCE
#include <Python.h>
What did it mean? How to link python.h and a matplotlibcpp.h in Visual Studio 2019?
Updates:
I was able to locate "Python.h" and "numpy/arrayobject.h" in MS python folder. However, when I manually added those three ".h" files into the project header folder, the issue wasn't resolved. Especially, when I manually fixed the locations in "matplotlibcpp.h", the "Python.h" in ""numpy/arrayobject.h" still could not be located.
Related
I am trying to bind my CPP function and use it in python code using pybind11. I have created a visual studio project that includes the function (does not have the main function). I cloned pybind11 from git and added it and python38 /include folders to Configuration Properties/VC++ Directories/Include Directories and python38 /libs folder to Configuration Properties/VC++ Directories/Library Directories. Also, I added the python38.lib file to Linker/input/Additional Dependencies.
I added
#include <Python.h>
#include <pybind11/pybind11.h>
to the top of my code. And the lines
And I get build errors of the form "unresolved external symbol
"LNK2001 unresolved external symbol __imp_PyThread_tss_create"
PYBIND11_MODULE(my_kmeans, handle)
{
handle.doc() = "Kmeans Clustering";
handle.def("my_kmeans", &kmeans, "kmeans function");
}
Can you please help me fix them?
I tried looking for a .lib file in pybind11 folder but I did not find one.
I used the visual studio installer to install python and could run the basic python program.
Now I want to make a new c++ console program and call the python script from there.
When googling I saw I need to include the "Python.h" in my c++ function. I tried to include and i get the message "cannot open the source file" . Is it because I used visual studio to install the python. And most of googling have installed python separately.
Older versions of visual studio, just installed python interpretter. So installed Visual studio 2019 and had a option to select Python3
With that option , it created a new directory, C:\Python27amd64\
Now I created a new console application:
Code:
#include <iostream>
#include "C:\Python27amd64\include\Python.h"
int main()
{
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is',ctime(time()))\n");
//std::cout << "Hello World!\n";
}
And also followed the following steps :
Properties > C/C++ > General > Additional Include Directories. I added the "C:\Python27amd64\include"
2.Properties > Linker > General > Additional Library Directories. : I added C:\Python27amd64\libs
3.Properties > Linker > Input > Additional Dependencies: I added python27.lib
I changed the build to "Release x64". Because it couldnot find the debug libraries
I am trying to install Lapack on my Windows 7 64bit to use SciPy. I have run into many different answers about this topic but I have not seen anywhere anything about this.
I am following the guide from this website: https://icl.cs.utk.edu/lapack-for-windows/lapack/ from the section "Easy Windows Build". As the site states, I need to install CMAKE, Visual Studio and download lapack. I have installed "cmake-3.5.0-rc3-win32-x86", "Visual Studio 13" and minGW with all the packages that were available (just in case).
Finally, when I open the "cmake-gui" (as administrator) to perform the steps it says to build "Lapack" and I specify my source code folder (the lapack decompressed folder "lapack-3.6.0") and my output folder (a folder in Documents) and I click the Configure button I get the following error message:
Error in configuration process, project files may be invalid
I checked the log files of cmake and this is what I get:
CMakeError.log
Compiling the Fortran compiler identification source file "CMakeFortranCompilerId.F" failed.
Compiler: C:/MinGW/bin/gfortran.exe
Build flags:
Id flags:
The output was:
The system cannot find the file specified
Checking whether the Fortran compiler is Compaq using "-what" did not match "Compaq Visual Fortran":
gfortran.exe: error: unrecognized command line option '-what'
gfortran.exe: fatal error: no input files
compilation terminated.
Checking whether the Fortran compiler is NAG using "-V" did not match "NAG Fortran Compiler":
gfortran.exe: error: unrecognized command line option '-V'
gfortran.exe: fatal error: no input files
compilation terminated.
Determining if the Fortran compiler works failed with the following output:
Change Dir: C:/Program Files (x86)/LAPACK/CMakeFiles/CMakeTmp
Run Build Command:"devenv.com" "CMAKE_TRY_COMPILE.sln" "/build" "Debug" "/project" "cmTC_249e8"
Generator: execution of make failed. Make command was: "devenv.com" "CMAKE_TRY_COMPILE.sln" "/build" "Debug" "/project" "cmTC_249e8"
CMakeOutput.log
The system is: Windows - 6.1.7601 - AMD64
Determining if the Fortran compiler is GNU succeeded with the following output:
# 1 "C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/CMakeTestGNU.c"
# 1 "<command-line>"
# 1 "C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/CMakeTestGNU.c"
void THIS_IS_GNU();
void THIS_IS_MINGW();
I have installed MinGW and I checked it is under the directory:
C:/MinGW
since I have also specified native compilers for CMAKE from inside the bin folder
gfortran.exe
gcc.exe
g++.exe
for Fortran, C and C++ respectively.
I checked online about the error in configuration process and from what I found out is that I need to have installed Visual Studio but I already have that.
Finally, I added the directory
C:\MinGW\bin
to the PATH variable.
Any suggestions as to why I cannot get to install LAPACK would be helpful.
Thank you
I basically did the same as the person here:
Building/including Boost.Python in VS2013
However, I used an empty cpp file with only the main function and the inclusion of <boost/python.hpp>
#include <boost/python.hpp>
int main() {
return 0;
}
Now I get the strange linker error (in Visual Studio):
1>LINK : fatal error LNK1104: cannot open file 'boost_python-vc140-mt-gd-1_60.lib'
Which is strange, because I have the lib file I think, however, it is called:
libboost_python3-vc140-mt-gd-1_60.lib
You need to configure your Visual C++ project setting.
The following case operates well.
[debug platform mode] x64
[include directory] (..\;;);C:\boost\boost_1_60_0\;C:\Python35\include\; # add your actual boost and python directory path
[library directory] (..\;;);C:\Python35\libs\;C:\boost\boost_1_60_0\stage\lib; # add your actual boost and python library path
I'm using Xcode. I got an error on this new mac:
'Python.h' file not found.
At line:
#include <Python.h>
When I type sudo find / -name "Python.h" in command line, I can see quite a few version of it exist, even inside Xcode.
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h
/System/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h
Anyone have any idea of what is going on? Is that I am not setting up Xcode properly?
You need to set the include path where 'Python.h' exists.
For detailed operation, please refer the question "How to set include path in xcode project" at following URL.
How to set include path in xcode project