Giter Site home page Giter Site logo

microsoft / python-sample-vs-cpp-extension Goto Github PK

View Code? Open in Web Editor NEW
75.0 23.0 35.0 18 KB

This sample is the end product for the walkthrough on https://docs.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio

License: MIT License

Python 51.02% C++ 48.98%

python-sample-vs-cpp-extension's Introduction

python-sample-vs-cpp-extension

This sample is the end product for the walkthrough on https://docs.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio. You must have the "Python native development tools" option selected for the Python development workload in the Visual Studio 2017 installer.

The superfastcode and superfastcode2 projects contain identical implementations of a hyperbolic tangent function. In the superfastcode project, the module is exposed to Python using the extension methods for CPython. In the superfastcode2 project, the module is exposed using PyBind11.

The CppAndPython project contains a little Python code that implements the same function using straight Python, then runs all three implementations to provide comparative results. Note that you may need to update the selected environment under the Python Environments node. The sample was written for Python 3.6 (32-bit). Make sure a suitable environment is selected here.

Because the superfastcode and superfastcode2 C++ projects contain a few hard-coded pathnames and is also configured to compile using the Visual Studio 2017 toolset, you may need to change a few project properties as described in the table below to make them work on your computer. For the latter two properties, just set the PYTHONPATH environment variable accordingly, which is the only change needed for Visual Studio 2017.

Project Property Value in the example Notes
Configuration Properties > General > Configuration Toolset Visual Studio 2017 (v141) If using Visual Studio 2015, change to Visual Studio 2015 (v140). In the VS 2015 installer, also make sure that you have the Programming Languages > Visual C++ > Common Tools for Visual C++ 2015 option selected, which includes the toolset.
C++ > General > Additional Include Directories %PYTHONPATH%\include Property must point to the "include" folder of your Python installation.
Linker > General > Additional Library Directories %PYTHONPATH%\libs Property must point to the "libs" folder of your Python installation.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

python-sample-vs-cpp-extension's People

Contributors

blackmist avatar kraigb avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar msftgits avatar vibhu-agarwal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-sample-vs-cpp-extension's Issues

$(PythonHome)

I wondered where $(PythonHome) is declared.
I followed "Create a C++ extension for Python" tutorial, but still, my c++ project can't get $(PythonHome) as the superfastcode2 example.
Python Environments are setup correctly in the solution.

Using python311 causes a runtime error

I'm getting an error when stepping through the line:
from superfastcode import fast_tanh

Fatal Python error: _PyInterpreterState_GET: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: unknown

Problem when I import module

I follow the step, copy the module.cpp but when I import the .pyc, there is a problem that

Message=dynamic module does not define module export function (PyInit_superfastcode)
Source=C:\Users\xmmzz\Desktop\py_C_code\Python_test\Python_test\Python_test.py
StackTrace:
File "C:\Users\xmmzz\Desktop\py_C_code\Python_test\Python_test\Python_test.py", line 30, in
import superfastcode

how can I solve the problem. Is that I am doing something wrong?

PYBIND11_MODULE MSVC 2017 python 3.6 issue: Python Version mismatch

Hey,
I was following the microsoft visual studio guide on how to setup a python wrapper for c++ via pybind11 here: https://docs.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio?view=vs-2017 . However after following the instructions my PYBIND11_MODULE within MSVC 2017 seems to think that there is a python version mismatch. Also when I try to build I run into numerous error such as:

  • E0020 identifier "ULONG" is undefined superfastcode2 1006

When I deprecated the project to use python 2.7 everything worked as expected. I was curious if anyone knew any solution to this since I would like to use python 3.6 or greater. I am relatively new to developing on Windows so sorry if my question seems a little basic. Thanks!!!!

C++ project properties problems

I have downloaded Python and C++ code and created VS Solution/Project as per MSFT web page instructions and Github code and instructions. The Python works perfectly. But, when I try to set the C++ properties, the "General>Target Extension: .pyd" property is not available. When build is attempted, an error message 'unresolved import supercodefast' " occurs. I checked my installation with the installer several times and have checked "Python native Development Tools" options. But when I revisit the installer, it is unchecked and appears to not have been installed. I am using VS Community 2019 with 32-bit Python and C++. This problems is probably some misunderstanding on my part, but could be a bug? Guidance to find and fix issues will be greatly appreciated. I have many needs for Python C++ extensions. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.