I have a C++ static library .lib that I wrap with cython to create a python extension module. I have been able to build the library and extension module with debug information and attach the Visual Studio Community 2015 debugger to the python process and debug the C++ code.
Now I would like to profile the C++ code using instrumentation. If I chose the VS2015 performance wizard option for instrumentation I can only select projects that are either executables or dlls, I can't select the static library project where my code is. I guess that if I could direct VS to use the python .pyd extension module that may work as it's a dll. However, I don't know how to do that.
I have also tried to find some way of starting the profiler while having the debugger attached to the python process, the same way I do for debugging the C++ code, but I haven't found a way. I can see the PerfTips while stepping through the code, but that's not enough.
Does anybody know how could I profile the C++ code in this static library?
Ultimately, if I can't find a way, I could create another VS2015 executable project and call my lib code from there, then profile the executable project. The only inconvenience with this approach is that I'm passing a few multidimensional arrays from python to the extension module and I would have to first save them from python and then load them in the C++ executable project. I'm not sure how will I do it, but it's doable. It would just be a lot more convenient for me if I was able to profile the C++ lib code when being called from python as I'm going to be doing that multiple times in the future and having to save the python data and then loading it from C++ each time it's a bit of a hassle.
Related
Background: I've successfully used pybind11 in a Visual Studio 2022 MSBuild project to create a .pyd library of C/C++ functions which can be imported into python code directly using the instructions here: https://learn.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio?view=vs-2022
Problem: Intellisense in VS2022 doesn't seem to recognize the imported module contents and display the expected autocomplete pop-ups or hints about exported functions/symbols/signatures/etc when coding in a .py file which imports this .pyd library. Intellisense does seem to know the library exists (i.e. no warning/error squiggles under the import directive).
Question: Is it possible to enable Intellisense to provide details about the imported module like it would when importing a .py file? Either via some configuration flags or additional content added to the PYBIND11_MODULE(){} section of the C/C++ code?
(Note this was not with Visual Studio Code or a CMake project, but I would be interested if this common problem exists for those tools in case the fix is similar. This discussion is along similar lines, but relevant VSCode and mentions something called pydoc which doesn't come up in the instructions linked above from Microsoft.)
I've been trying to include Python.h into my application, but I wanted to do it statically so it can be a standalone exe that knows how to run python on its own. I've tried using the dlls and using something like iexpress to bundle the two, however, even with that method the user needs to have Python on their system path to run it, which just ruins all the convenience. Whenever I try to build python with cmake or some other methods I've seen online, there are always just very obscure errors, and fixing them just leads to more. Anyone know how to statically build python for windows, or does someone maybe already have it built?
I know there is some way to call Python from C++, like Python/C API or Boost.Python. My question is, how can I distribute the application? For example, does user still need to install Python and Python packages on their machine?
My user case is: I want to use some Python code from my C++ code. The main application is written in C++. Then I am going to deploy my app. The goal is to make the app self contained, and user don't need to install Python and Python packages at all.
The possible steps may be :
1, calling Python from C++ via Python/C API or boost.Python from source code.
2, bring Python/C libraries together with application.
I hope after these 2 steps, my app will be a self-contained and standalone software. User can just copy the app folder to any other machines which has no Python installed.
Note that due to license issue, I can not use PyInstaller. I also meet some problems when trying to use "Nuitka" to make the Python part self contained. So I am now trying directly calling Python from C++. I know it will run on my developer machine. But needs to confirm that this solution can also make app self-contained and won't ask user to install Python.
Update: Now I feel I need to do something to make my app self-contained if I use Python/C to call python from C++ :
1, I need to bring all needed runtime with my app. (C++ runtime of course, and the python_version.dll)
2, I need to deploy a Python interpreter inside my app. Simply copy the Python folder from Python installation and remove some not needed files (like header files, lib files)
3, use Py_SetPythonHome function to points to the copied Python interpreter inside the app.
I'd say you're on the right track. Basically, you should obtain a Python (shared or static) library, compile your program with it, and of course bundle the Python dependencies you have with your program. The best documentation I've read is available here: https://docs.python.org/3.8/extending/embedding.html#embedding-python-in-another-application. Roughly, the process is:
Get a Python library from python.org and compile with ./configure --enable-shared (I believe omitting --enable-shared does only produce the python binary).
Compile your program. Have it reference the headers under Include and link the library. Note that you can obtain the compiler and linker flags you need as described here.
Call Python code from within your application using e.g. PyRun_SimpleString() or other functions from the C API. Note that you may also depend on the Python standard library (under Lib in the distribution) if there's any functionality you use from it.
If you linked against Python statically, at this point you're done, aside from bundling any Python code you depend on, which I'm not sure is relevant in your case.
I am suffering from the same problem, I had a project which is made up of C++ and python(embedded) and there is a problem of deployment/distribution.
After research, I got a solution which is not perfect (means it will be helpful to run your app in other system)
change visual studio in release mode and compile(you got a folder in your working directory)
install pyinstaller (pip install pyinstaller)
then navigate to pyinstaller folder and command:-pyinstaller.exe "your script_file_path.py"
-it will create a dist folder
copy that folder in working folder where exe exists.
remember.
dist folder and c/python code compiled by same version of python.
now good to go.
it will work.
I am using pythonnet ( https://github.com/pythonnet/pythonnet ) and have referenced a .Net library within the same solution space but it does not seem to pull in any information to use for Intellisense. In fact, VS gives an error:
"Unable to resolve "ReferenceLibarary". Intellisense may be missing for this module.
So how do I add intellisense to my "module"?
Even though there is an error, the script can still be run (in or out of VS). I have thorough XML already set up as there is also a sandcastle project for a chm output. Can the sandcastle project output the appropriate content that is missing?
Peter Stevens answer seems fine to me. His solution uses IronPython to generate stubs. These stubs are used in turn by the CPython auto-completion mechanism, in for example, Visual Studio Code.
Let's say you have a c# dll located in c:\dev\HTL\bin\release\HTL.dll you want to access from Python and need auto-completion to help code. With IronPython installed and the ironpython-stubs module downloaded, you can do the following:
ipy -m ironstubs make HTL --path="c:\\dev\\HTL\\bin\\release\\HTL.dll" -output stubs.min
Then, as in Peter's response above, in VS Code use File | Preferences | Settings to add the full stubs.min path to "python.autoComplete.extraPaths". Having imported the target dll into your *.py file in the VS Code editor you should now be able to dot to auto-completion for the classes contained in that dll.
Use the ironpython-stubs module.
Make sure your dll is in sys.path, then run from ironpython
ipy -m ironstubs make --output stubs.min
then set "python.autoComplete.extraPaths" to \ironpython-stubs\release\stubs.min
Works like a charm
I have no development experience in Qt/KDE and Python, but I know Windows CE development using Visual Studio for mobile platforms. My requirement is to build the open object client https://launchpad.net/openobject-client-kde for Windows CE 5.2 devices.
I have downloaded the sources from http://sourceforge.net/p/ktiny/code/HEAD/tree/ but don't know what to do with it. I understood those source contains Python and Qt files.
Could someone please let me know how I can build/compile the downloaded sources? I am using Windows 8, and what are the SDK/IDE/Libs that are to be configured
Thanks in Advance
#nish
The source you downloaded does contain "Qt files" only in a sense. What it really has is various build scripts, C++ source files, .ui xml and .qml files for user interface generation. The C++ and .ui sources need to be run through code generators (moc and uic, respectively), to generate more C++ code.
"All" you do to get this code to work is to compile it using whatever build system it uses and link it with the Qt library.
The first step is to get a working Qt build for your target platform. You need to get to a point where you have the examples included with Qt running on your Windows CE 5.2 device. Until you get to that point, there's no reason whatosever to even look at the openproject files themselves. If you can't get bare Qt to work on your target, you're toast.
The second step is to figure out the dependencies of the openobject client project - does it really need KDE, and to what extent?
Thirdly, you have to acquire and build those dependencies, and make sure that they work on your target platform. For KDE, there's plenty of example applications that you can use to try things out.
Lastly, you'll get to build the openobject code itself.
Note that it's very likely that none of the projects you'll be building include any Visual Studio project files, so you'll be running all of the build using various commandline build tools.
It'll be, in fact, likely easiest to do the builds using Qt Creator rather than Visual Studio, since Visual Studio doesn't really support out-of-the-box any build systems other than its own. Note that Visual Studio has two main components: the IDE, and the compilers with requisite runtime libraries. You don't need to use the former to use the latter.
As-is, though, your question is way too broad and you'll need to come back and ask separate questions as you run into individual problems.