有人试过使用 pycharm 远程调试里面的 IPython notebook 吗

最全Pycharm教程(33)——使用Pycharm编写IPython Notebook文件
  1、主题
  详细介绍如何使用PyCharm创建一个IPython Notebook(基于Web技术的交互式计算文档格式)并运行。
  2、准备工作
  (1)已经创建一个工程,这里使用C:/SampleProjects/py/IPythonNotebookExample目录下的工程。
  (2)在设置对话框的页面中,
    创建一个虚拟环境,这里创建了针对Python.2.7.8的虚拟环境
    安装了以下库:
Jinja2ipythonmatplotlibnumpypyzmqtornadosympy
  当然Pycharm可以帮助我们自动进行安装。
  3、创建一个IPython Notebook文件
  右击工程名,选择New → File:
  输入名称及其外部扩展&MatplotlibExample.ipynb:
  此时在显示了一个新创建的文件:
  双击打开它,这是一个空的IPython Notebook文件,以为标记,并有着与真正的IPython Notebook非常相似的工具栏:
  4、填充并运行一个文件胞
  单击第一个元胞,输入代码,这里键入matplotlib库的配置代码:
  单击工具栏上的(或者Shift+Enter)运行,Pycharm会弹出一个对话框显示IPython Notebook服务运行的URL地址:
  单击OK:
  可以通过浏览器来打开这个链接:
  在设置对话框中的&中指定了其默认的URL。接下来我们开始真正使用IPython Notebook。
  5、使用cells
  首先,写上import语句:
  当你运行第一个cell时,Pycharm会默认创建下一个空的cell:
  输入代码(体会拼写助手功能):
  单击再次运行,无输出,但有创建了一个新的cell。
  在新的cell里面输入如下代码;
  运行这个cell,报错:
  变量需要提前定义,因此我们再添加一个新的cell。
  6、添加cell
  单击import语句所在cell(变绿框),单击绿色的加号(或者是Alt+Enter快捷键):
  输入变量定义代码:
  先运行这个cell,在运行下一个cell,输出正常:
  7、cell的剪贴板操作
  在工具栏中,除了和按钮,还有(Ctrl+X)、(Ctrl+C)以及(Ctrl+V)按钮,如果单击,则删除当前cell,并将其缓存于剪贴板上。
  是粘贴,是复制,其余按钮功能大家自己体会。
  8、选择风格
  工具栏右侧下拉菜单用于指定界面风格,这里默认为code分割。
  单击import语句的cell,单击,默认创建code风格的cell,输入一下代码:
  单击下拉箭头选择Markdown模式:
  cell外观发生响应改变:
  单击:
  OK,接下来可以选择你喜欢的style类型:
  9、输入格式
  添加一个新的cell,选择Markdown格式,输入以下代码:
  单击:
  正如你所见,IPython Notebook可以实现Latex格式的公式编辑。
  接下来尝试更复杂的功能,显示公式的计算结果。添加一个cell,输入一下代码(来自):
  运行,无输出,继续添加cell,输入代码:
  单击,享受结果吧:
看过本文的人也看了:
我要留言技术领域:
取消收藏确定要取消收藏吗?
删除图谱提示你保存在该图谱下的知识内容也会被删除,建议你先将内容移到其他图谱中。你确定要删除知识图谱及其内容吗?
删除节点提示无法删除该知识节点,因该节点下仍保存有相关知识内容!
删除节点提示你确定要删除该知识节点吗?jupyter安装小结
投稿:hebedich
字体:[ ] 类型:转载 时间:
jupyter (之前的 ipython notebook )于我的最大意义在于,让学习进程和探索进程变得可累积,正如它的原先名字中的 notebook 所暗示的那样,作为学习的记录者,方便你随时捡起学习的进度,增量式地前进
前段时间一直使用pycharm写pandas程序,对于大数据开发而言,开发一般是走一步想一步,pycharm不适合。网上推荐使用jupyter notebook,它是一个web版的编辑器,原来是IPython的一部分,后来拆分出来了。安装了一把,发现比较麻烦,网上的资料也比较老了,不适合。总结一下与大家分享。
我是ubuntu系统,我是通过pip安装的。
Pyzmq是zeromq的Python绑定。zeromq是一个消息内核,从网络通信的角度看,它处于会话层之上,应用层之下,有了它,你甚至不需要自己写一行的socket函数调用就能完成复杂的网络通信工作。
安装命令:
pip install pyzmq
安装tornado
Tornado是python编写的非阻塞式服务器,它使用epoll管理连接,每秒可以处理数以千计的连接,是一个理想的 Web 实时处理框架。
安装命令:
pip install tornado
安装Jinja2
Jinja2是Python下一个被广泛应用的模版引擎,他的设计思想来源于Django的模板引擎,并扩展了其语法和一系列强大的功能。其中最显著的一个是增加了沙箱执行功能和可选的自动转义功能,这对大多应用的安全性来说是非常重要的。
安装命令:
pip install jinja2
安装jsonschema
jasonschema 用来描述Json数据格式,Json模式有多种用途,其中之一就是实例认证。
安装命令:pip install jsonschema
安装jupyter
从前面安装的组件可以看出,jupyter实际就是个tornado框架的web应用,使用MQ进行消息管理。
安装命令:pip install jupyter
这个安装遇到了一些问题,安装jupyter成功了一半,只可以编辑文档,但是不能进行python程序运行。
后来导致我执行pip list也失败了,最后将pip 升级了一把,然后卸载jupyter,再重新安装,工作正常了。ubuntu安装还有权限问题,我最后是通过root权限安装的jupyter。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具  一个好的编译器对于我们处理日常的科研很关键,好的编译器无论是从界面,字体风格,提示,调试等各方面都能从用户角度出发,提供最好的使用体验。Python本身自带的IDLE或者在CMD里进行操作和调试,对于小型的测试程序和学习的时候是可以的;但是对相对比较大的程序,它们就显得有些力不从心了,首先是查找和提示的,还有就是当你想要改变程序中某个变量或者函数的名称,一个个查找是让人奔溃的事情。
  本人显示从IDLE和CMD开始Python码城过程的,慢慢的发现,相对于以前使用的VS和eclipse,它们显得太LOW了。我开始尝试在sublime里面进行编辑,给sublime装插件,能够直接运行Python程序(Ctrl+B),以及进行代码智能提示。sublime用了好长一段时间,还是比较好用的,代码的显示也比较让人愉悦,你也可以按自己的喜好去进行配置。总的来说,还是比较推荐sublime的。还有就是pycharm了,有很多的Python开发者使用它,PyCharm确实是Python开发之首选。我也用过一段时间,习惯了sublime,就没太多的去研究,总体来说也还是比较推荐的编译器之一。
  后来在别人的博客中看到了ipython,它是一个Python交互式的shell,比默认的shell要好用,支持变量的自动补全,自动缩进,支持bash shell命令,内置了许多很有用的功能和函数。安装也很简单,windows下直接在命令行输入:python &m pip install IPython。最让人惊喜的是,ipython中提供了一下简单好用的magic函数。以下是百度上列举的常用命令:
%bg function把 function 放到后台执行,例如: %bg myfunc(x, y,z=1),之后可以用jobs将其结果取回。myvar = jobs.result(5) 或 myvar =jobs[5].result。另外,jobs.status() 可以查看现有任务的状态。
%ed 或 %edit编辑一个文件并执行,如果只编辑不执行,用 ed -x filename 即可。
%env显示环境变量
%hist 或 %history显示历史记录
%macro name n1-n2 n3-n4 ... n5 .. n6 ...创建一个名称为 name 的宏,执行 name 就是执行 n1-n2 n3-n4 ... n5 .. n6 ...这些代码。
%pwd显示当前目录
%pycat filename用语法高亮显示一个 python 文件(不用加.py后缀名)
%save filename n1-n2 n3-n4 ... n5 .. n6 ...将执行过多代码保存为文件
%time statement计算一段代码的执行时间
%timeit statement自动选择重复和循环次数计算一段代码的执行时间,太方便了。
  然而百度漏掉了比较常用的%run,可以用来运行外部的Python脚本。还有**??来显示某个模块用法,如import os,os??。其他的包括查看变量的值,代码运行效率检查等。下次我将单独开一篇讲常见的magic命令,这次就不多赘述。
  说完自己选择编译器进行开发的过程,终于要来到我们的重点了&&Anaconda。一个偶然的机会,看到师兄使用ipython notebook进行汇报,可以在页面进行代码和文档排版编写,对于科学计算非常方便。ipython notebook是web based IPython封装,但是可以展现丰富文本,使得整个工作可以以笔记的形式展现、存储,对于交互编程、学习非常方便。关于ipython notebook的具体使用,找机会单独另开一节,在此不是重点。下图是它的页面,在上面还可以用markdown标记编辑文本。可以呈现很不错的文档页面。
  Anaconda是一个集成的环境,现在已经升级到Anaconda2了,直接下载安装,很方便,集成了Python,ipython,notebook,Spyder和qtconsole,如下所示。之前的ipython notebook也改为了jupyter notebook。
  Anaconda是一个和Canopy类似的科学计算环境,但用起来更加方便。自带的包管理器conda也很强大。Anaconda提供了Python2.7和Python3.4两个版本,同时如果需要其他版本,还可以通过conda来创建。
  下面来看一下conda。输入 conda list 来看一下所有安装时自带的Python扩展。粗略看了一下,其中包括了常用的 Numpy , Scipy , matplotlib 和 networkx 等,以及 beautiful-soup , requests , flask , tornado 等网络相关的扩展,还有常用的科学工具包,scikit-image,scikit-learn等。其他没有的包可以通过pip,easy_install安装,也可以通过它特有的conda来进行安装,conda install ***,如果需要指定版本,也可以直接用 [package-name]=x.x 来指定。conda的repo中的扩展不算太新,如果想要更新的,可能要用PyPI或者自己下载源码。而conda和pip关联的很好。使用pip安装的东西可以使用conda来管理,这点要比Canopy好。
这个科学计算环境的另一个要求就是能够多个Python版本并存,尤其是2.x和3.x的并存。这个通过 virtualenv 可以做到。Anaconda也正是通过其实现的。
下面用conda创建一个名叫python3的版本为python3.4的环境。
conda create -n python3 python=3.4这样就会在Anaconda安装目录下的envs目录下创建python3这个目录。
向其中安装扩展可以:
直接用 conda install 并用 -n 指明安装到的环境,这里自然就是 python3 。像 virtualenv 那样,先activate,然后在虚拟环境中安装。
spyder就是一个Python的扩展,也是比较好用的,感兴趣的可以自己亲自尝试下,它里面的查看变量的功能还是很方便的。
阅读(...) 评论()2866人阅读
python环境搭建(2)
Pycharm中使用Ipython编写交互式notebook
1.安装Anaconda。
建议直接下载安装Anaconda,其中包含丰富的库,以及我们接下来需要使用的Ipython。所有的操作都一步到位,具体从Pycharm调用Anaconda可参考百度。anaconda下载技巧详见
2. 新建工程文件,选择Jupyter Notebook,即IPython Notebook file,文件的后缀为.ipynb。
3.编辑代码。其中In[index]表示输入框(可以多行或者单行),点击运行&&(或者&Shift+Enter),如果有输出,则会在其下方对应显示,同时会自动新建一个In[],唯一缺点是你又要用鼠标点击才能到编辑区域,这点希望有个快捷键。Out[index]表示输出,[index]表示序号。每一次针对特定输入序号的运行都会使In[index++]的序号增加,相当于与序号记录了代码运行的顺序,如果你闲的没事,又把前面的代码改了,运行之后前面的序号也会更改,所以会导致序号错乱,不方便查看,所以一般最后会清除所有序号,即点击那个旋转的重置符号Restart
kernel,重新走一遍。而Out[index]则一直和In[index]保持一致。
Ipython其实相当于一个调试工具,只能按照你编写的顺序一步一步执行,继承并且可视化你的每一步操作。
所以最好的开发思想是:在每个模块化的Cell里编写代码,单步调试,反复论证,最终调试通过后,点击重置符号Restart
kernel,按顺序最后过一遍程序,达到重新编号同时检验代码先后顺序的作用,最后把所有代码汇总在一个.py文件中,作为最终的成果。同时当程序全部调通了,最后将其放入checkpoint文件夹中作为最终notebook文件,以供分享和展示。
第一次运行会提示确认IPython的URL,这样就可以在浏览器中查看你的ipython notebook了。如果提示token,一般是notebook出问题了,先点击取消,然后会提示打开jupyter notebook,出现诸如fix修正notebook,重新下载和安装之类的提示,直接联网照做即可。
4.&表示在选定In[]下增加一行输入,&&(Ctrl+X)表示剪切(而ipython没有删除,所以这个很常用),&&(Ctrl+C)复制之后的运行In[index]会增加
,&(Ctrl+V)
粘贴在所选代码的下一行,表示将输入序号重置,这样就相当于一个Notebook文件中有两个分别独立的文件,之前的变量定义,库的导入,对重置后的代码无效,所以强烈建议不要用,但是对于另起炉灶的还是可以考虑,这样就和之前的变量没有关系了。同时右键Split Cell很有用,可以拆分Cell,对应的合并也是一样。
5.其余的关于文本标题的编辑,以及markdown主要用于说明注释,就不详细说明了。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:5811次
排名:千里之外
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'IPython Notebook with PyCharmUsing IPython/Jupyter Notebook with PyCharmIn this section:Before you start
Prior to executing the tasks of this tutorial, make sure that the following prerequisites are met:
You have a Python project already . In this tutorial the project
C:/SampleProjects/py/IPythonNotebookExample is used. In the
page of the
Settings/Preferences dialog, you have:
. For this tutorial a virtual
environment based on Python 3.5.0 has been created.:
Note that PyCharm automatically installs the dependencies of these packages.
Creating a IPython Notebook file
In the , click Alt+Insert. Then, on the pop-up
menu that appears, choose the option Jupyter Notebook and type the file name (here it
is MatplotlibExample.ipynb).
The newly created file now shows up in the
and automatically
By now, the new file is empty, but PyCharm recognizes it as a
As such, this file is marked with the icon
and features a toolbar, which is a complete
replica of the real IPython Notebook toolbar:
Filling in and running the first cell
This is most easy. Just click the first cell and start typing. For example, in the very first cell type the
following code to configure the matplotlib package:
%matplotlib inline
Next, click the icon
to run the cell (alternatively, you can press
Shift+Enter). PyCharm shows a dialog box, where you have to specify the URL where
the IPython Notebook server will run:
The console shows the server URL:
Follow this address:
Note that the default URL is specified in the IPython Notebook page of the Settings/Preferences dialog:
Actually, that's it... From now on you are ready to work with the notebook integration.
Working with cells
First of all, add the following import statement:
from pylab import *
This how it's done. As you might have noticed, while you've run the first cell, PyCharm has automatically
created the next empty cell:
Start typing in this cell, and notice :
on the toolbar again to run this cell. Note that the cell produces no output, but the
next empty cell is created automatically. In this new cell, enter the following code:
plot(x, y, 'r')
xlabel('x')
ylabel('y')
title('title')
Run this cell. Oops! The attempt to run results in an error:
It seems that the variables should be defined first. To do that, add a new cell.
Since the new cell is added below the current one, click the cell with import statement - its frame
becomes green. Then on the toolbar click
(or press Alt+Insert).
In the created cell, type the following code that will define x and
y variables:
x = linspace(0, 5, 10)
y = x ** 2
Run this cell, and then run the next one. This time it shows the expected output:
Clipboard operations with the cells
Look at the toolbar. There are
(Ctrl+X), and
(Ctrl+V) buttons.
If you click , you thus delete the current cell, and take it into
the clipboard.
results in inserting the contents of the clipboard
below the current cell. Finally,
just duplicates the current cell.
Try these buttons yourself.
Running and stopping kernels
As you've already learnt, the button
is used to execute a cell.
If calculation of a certain cell takes too much time, you can always stop it. To do that, click
the document toolbar.
Finally, you can rerun the kernel by clicking
on the document toolbar.
The messages about all these actions show up in the console:
Choosing style
Look at the drop-down list to the right of the document toolbar. It allows you to choose presentation
style of a cell. For example, the existing cells are presented as code.
Click the cell with the import statement again, and then click . The new cell appears
below. By default, its style selector shows Code. In this cell, type the
following text:
plot example
Next, click the down arrow, and choose Markdown from the list. The cell changes its view:
on the toolbar, and how the cell looks now:
Now you can just select the desired style from the drop-down list, and the view of the cell changes
appropriately:
Writing formulae
Add a new cell. In this cell, choose Markdown from the style selector, and type the following text:
$$c = \sqrt{a^2 + b^2}$$
Click . The result is stunning:
As you see, PyCharm's IPython Notebook integration makes it possible to use
and render formulae, labels and text.
Next, explore the more complicated case. The expected result - the formula - should appear as the result of calculation.
Add a cell and type the following code (taken from
from __future__ import division
from IPython.display import display
from sympy.interactive import printing
printing.init_printing(use_latex='mathjax')
import sympy as sym
from sympy import *
x, y, z = symbols(&x y z&)
k, m, n = symbols(&k m n&, integer=True)
f, g, h = map(Function, 'fgh')
Run this cell. It gives no output. Next, add another cell and type the following:
Rational(3,2)*pi + exp(I*x) / (x**2 + y)
and enjoy:
Procedures:External Links:Last modified: 23 December 2016

我要回帖

更多关于 pycharm调试 的文章

 

随机推荐