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
- Download Numpy-MKL 64-bit and install it.
- Download SciPy 64-bit and install it.
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的更多相关文章
- Python tools for Visual Studio插件介绍
Python tools for Visual Studio是一个免费开源的VisualStudio的插件,支持 VisualStudio 2010,2012与2013.我们想要实现的是: ...
- windows下使用python操作redis(Visual Studio Code)
1.编辑工具: Visual Studio Code(windows环境) 2.redis服务器:这里用了远程连接,需要配置redis.conf. (1)注释 #bind 127.0.0.1 (2)设 ...
- Building Python 2.7.10 with Visual Studio 2010 or 2015 - Google Chrome
您的浏览器(Chrome 33) 需要更新.该浏览器有诸多安全漏洞,无法显示本网站的所有功能. 了解如何更新浏览器 × p-nand-q.com C++ Python Programming L ...
- Visual Studio 2012 Ultimate 上安装 Python 开发插件 PTVS
1.我的环境 操作系统:32位 Win7 旗舰版 Service Pack 1 VS版本:Microsoft Visual Studio Ultimate 2012 版本 11.0.50727.1 R ...
- Windows服务器Pyton辅助运维--03.安装Visual Studio 的 Python 开发插件 PTVS
PTVS (Python Tools for Visual Studio) http://pytools.codeplex.com/ 当前版本:2.1 RC PTVS (Python Tools fo ...
- Python 在Visual studio 中做单元测试进行TDD开发
Unit Tests Steve Dower edited this page on 14 Jul · 3 revisions Pages 38 Home Azure Remote Debugging ...
- visual studio 2015使用python tools远程调试maya 2016
步骤: 1. 去https://apps.exchange.autodesk.com/MAYA/en/Home/Index搜索Developer Kit并下载,maya 2016可以直接点击这里下载. ...
- Python+Visual Studio
一直在找一个比较好的Python IDE,无奈找来找去都不太好用,由于经常用Visual Studio,所以很希望找到一个能够在VS中的Python扩展.今天发现了一个很给力的VS扩展,可以在VS中方 ...
- 【Python】- 如何使用Visual Studio 2013编写python?
安装Visual Studio 2013 1.VS2013下载安装略 安装python2.7 1.从官网下载python2.7,下载地址:https://www.python.org/getit/ ...
随机推荐
- Alpha(2/6)
队名:無駄無駄 组长博客 作业博客 组员情况 张越洋 过去两天完成了哪些任务 任务分配.进度监督 提交记录(全组共用) 接下来的计划 沟通前后端成员,监督.提醒他们尽快完成各自的进度 还剩下哪些任务 ...
- 新建Class文件时,添加作者版权注释声明
以安装路径C盘为例,各版本路径如下: VS2015:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTempla ...
- [学习笔记] 二叉查找树/BST
平衡树前传之BST 二叉查找树(\(BST\)),是一个类似于堆的数据结构, 并且,它也是平衡树的基础. 因此,让我们来了解一下二叉查找树吧. (其实本篇是作为放在平衡树前的前置知识的,但为了避免重复 ...
- SpaceClaim脚本功能(Beta功能)
本操作仅适用ANSYS SpaceClaim 2016 打开SpaceClaim脚本编辑器的方法有两种 方法一(看截图操作): 方法二(请见后面的实例操作). 创建球体源代码: #定义 ...
- mac环境使用python处理protobuf
安装 brew install protobuf 然后再安装protobuf需要的依赖 brew install autoconf automake libtool 验证是否安装成功 protoc – ...
- spark_API
1.概述 总的来讲,每一个spark驱动程序应用都由一个驱动程序组成,该驱动程序包含一个由用户编写的main方法,该方法会在集群上执行一些并行计算操作.Spark最重要的一个概念是弹性分布式数据集,简 ...
- 服务器部署docker
docker简介 可以把docker是一个容器,可以让开发者将自己的项目部署到这个容器中,最常用的场景是将自己的后端项目部署到服务器的时候会将其打入docker镜像中,可以理解为一个开销更小的虚拟机. ...
- Flink 之 Data Source
Data Sources 是什么呢?就字面意思其实就可以知道:数据来源. Flink 做为一款流式计算框架,它可用来做批处理,即处理静态的数据集.历史的数据集: 也可以用来做流处理,即实时的处理些实时 ...
- 【JDBC】仅输入表名和要插入的记录数,自动检测表的字段和类型,然后插入数据的全自动程序(Oracle版)
之前写的批量插值程序只是五六半自动版本,因为表的字段还需要手工填写,这回只要指定表名和要插多少数据就行了,类似于全自动突击步枪,扣动扳机就把字段打完为止. 全自动程序如下,诸位拿下去后可以修改成自己想 ...
- ROS tf基础使用知识
博客参考:https://www.ncnynl.com/archives/201702/1306.html ROS与C++入门教程-tf-坐标变换 说明: 介绍在c++实现TF的坐标变换 概念: Co ...