Python/C++ in Visual Studio: An Alternative to Matlab/MEX

来自Andrew Delong的博客

http://andrewdelong.wordpress.com/2012/11/03/pythonc-in-visual-studio-an-alternative-to-matlabmex/

I spent much of my PhD working in Matlab with C++ MEX extensions. Debugging
MEX extensions is frustrating: either you resort to print statements, or you
wait for the IDE to launch a new Matlab every time you make a change.

With Microsoft’s release of Python Tools for Visual Studio,
I decided to switch to Python with C++ extensions.


The integration is exactly what I was looking
for: full debugging, auto-complete, real-time syntax checking, python console
(like Matlab), and profiling (needs Ultimate Edition of Visual Studio). Python
can load C++ extensions built with Visual Studio 2010/2012 just fine, even
though Win64 Python is itself compiled with Visual Studio 2008; the new
compilers are amust for using the wonderful features of C++11
.

Getting a Matlab-like setup for Win64 takes a few steps. For Linux, one has
the option of simply installing Free
64-bit EPD Python
,  a Python distribution that bundles several
packages for scientific computing (plotting, matrices, Intel MKL). 64-bit EPD
does not seem to be free for Windows users. So, the rest of this post is a guide
to set things up from scratch.

1. Install Python


  • Download Python 2.7 X86-64 and
    install it to the default location.

  • Make sure C:\Python27 is in your system path: open a command-prompt and
    run “python”; use “quit()” to exit the interpreter.

  • Add PYTHON_PATH=C:\Python27 to your system environment variables. (This
    will be convenient when setting up Visual Studio projects that link with
    Python, e.g. a C/C++ extension module).

2. Install Numpy-MKL and SciPy



3. Install Matplotlib


  • Download the latest Matplotlib-win-amd64-python2.7 and
    install it.

  • Test it by starting a python interpreter and running the commands

          import matplotlob
    import matplotlib.pyplot as plt
    plt.plot([1,2,2,3])
    plt.show()

    You should see a Figure window pop up.


  • [Optional] If you are annoyed by the 4-pixel grey margin around all figure
    windows,
    openC:\Python27\Lib\site-packages\matplotlib\backends\backend_tkagg.pyand
    find the place where it says “borderwidth=4“, then replace
    this
    with “borderwidth=0, highlightthickness=0“.

4. Install Visual Studio

If you are a student or staff at a university, you can get a free license for
Visual Studio Ultimate Edition (2010 or 2012) by getting a Microsoft DreamSpark
account through your department. However, these steps should work just fine with
the free Express Edition of Visual Studio as well. (Note that Python/C++ speed
profiling is only available in Ultimate Edition).

5. Install Python Tools for Visual Studio

Download Python Tools for
Visual Studio
 and install. Be sure to get the version for the IDE
you want to use (i.e. 2010 or 2012).

To see the new Python console, go to View->Other Windows and select
it. You can dock the new tool window with the rest.

Also enable the Python Debug Interactive window in Debug->Windows.

Notes

As of PTVS 2.0 Beta, mixed C++/Python debugging is available in VS 2012
or later.
 By default, breakpoints will only work in either
Python or C++ during any one debugging session — if you debug
using a Python “startup project”, breakpoints in your C++ code will be ignored
for that debug session; if you debug a C++ “startup project”, your Python
breakpoints will be ignored. If you want mixed debugging, you must explicitly
enable it in your Python project’s Debug settings (VS2012 only).

Tip #1: Python code will run slower when debugging; I find Ctrl+F5 (run
without debugging) immensely useful when I’m not planning to hit any
breakpoints.

Tip #2: By default Visual Studio will break when Python exceptions are
thrown. This is a problem because many Python modules use exceptions as a means
of ‘normal’ control flow (bad!), so you’ll want to tell the debugger to let most
exceptions slide. Go to Tools->Options->Debugging and select “Enable Just
My Code”.

Then go to Debug->Exceptions and uncheck the “Thrown” column for
Python

If a package imports “without debugging” but breaks when you run it “with
debugging” then you may even have to disable breaking on a User-unhandled
exception.

Python/C++ in Visual Studio: An Alternative to
Matlab/MEX

时间: 2024-10-10 12:29:07

Python/C++ in Visual Studio: An Alternative to Matlab/MEX的相关文章

在visual studio中可以调试运行PYTHON,强大,具体做法就是下载一个PTVS(Python tool for visual studio)

最近编写chromium代码,发现内部用了python作为工具做开发,于是得知有如此插件 安装PTVS后,vs调试python和C++代码一样,可以设置命令参数,调试时候,可以看变量值等等... 而且F5,F10,F11...快捷键保持 具体http://pytools.codeplex.com/

Python Tools for Visual Studio

http://microsoft.github.io/PTVS/   VS2013版本以下装PTVS 2.1 VS2013版本以上装PTVS 2.2.2 注意:在安装PTVS之前必须已经安装 VS,py,以及framework 4.5以上版本. 打开vs2010新建一个项目,其他语言-->python-->python application,建立好后出现一个.py文件,默认存在print('Hello World')这条语句,按下ctrl+F5执行.

Building Python 2.7.10 with Visual Studio 2010 or 2015 - Google Chrome

您的浏览器(Chrome 33) 需要更新.该浏览器有诸多安全漏洞,无法显示本网站的所有功能.?了解如何更新浏览器 × p-nand-q.com C++? Python? Programming? Languages? Humor? Tools? Misc? Building Python 2.7.10 with Visual Studio 2010 or 2015 7th revision, August 7, 2015.A document history can be found at t

Python 在Visual studio 中做单元测试进行TDD开发

Unit Tests Steve Dower edited this page on 14 Jul · 3 revisions Pages 38 Home Azure Remote Debugging AzureSDK Bottle and Azure Table Storage on Azure Bottle and MongoDB on Azure Browsing Code Using PTVS Build Instructions for PTVS Cloud Project Code

Windows服务器Pyton辅助运维--03.安装Visual Studio 的 Python 开发插件 PTVS

PTVS (Python Tools for Visual Studio) http://pytools.codeplex.com/ 当前版本:2.1 RC PTVS (Python Tools for Visual Studio) 是一个开源项目,采用Apache 2.0许可发布.PTVS的主要特性包括:CPython.IronPython.Jython和PyPy:高级编辑功能如IntelliSense:多重构:内置REPL(read-eval-print loop)窗口:调试和分析功能,等等

Visual Studio 2012 Ultimate 上安装 Python 开发插件 PTVS

1.我的环境 操作系统:Win7 旗舰版 Service Pack 1 VS版本:Microsoft Visual Studio Ultimate 2012 版本 11.0.50727.1 RTMREL 2.安装过程 PTVS(Python Tools for Visual Studio)是一个VS下的Python开发插件 OSC上PTVS的首页为:http://www.oschina.net/p/PTVS 下载页面为:http://pytools.codeplex.com/releases/v

如何使用Visual Studio 2013编写python?

安装Visual Studio 2013 1.VS2013下载安装略 安装python2.7 1.从官网下载python2.7,下载地址:https://www.python.org/getit/  如图: 下载是可执行文件,直接双击即可安装,安装路径保持默认(即:C:\Python27)即可. 2.环境变量的配置 将 C:\Python27(方便直接在cmd中运行python) 和 C:\Python27\Scripts (方便直接在命令行中安装whl文件)添加到windows环境变量中. 3

Visual Studio 2013进行python开发

安装Python Tools for Visual Studio 2013 直接在Vs2013中文件=>新建=>项目=>python:获取Python Tool for Visual Studio 下载Python Tool for Visual Studio即可,下载完成后进行安装 原文地址:https://www.cnblogs.com/zhangabo/p/11504236.html

Microsoft Visual Studio 2015 下载、注册、安装过程、功能列表、问题解决

PS:请看看回复.可能会有文章里没有提到的问题.也许会对你有帮助哦~ VS2015正式版出了,虽然没有Ultimate旗舰版,不过也是好激动的说.哈哈.可能有的小伙伴,由于工作环境不允许.或者害怕有什么问题.所以不敢安装vs2015.只能眼巴巴地干瞅着. 因此,我决定,冒一次重装系统的风险,试着安装一下,正好也试试什么序列号能用.希望这次牺牲能值得~~呵呵. 下载地址:Microsoft Visual Studio 2015 全版本+离线MSDN+全部插件 赶紧下载,打开,发现VS2015对安装