标签: ipython

"TypeError:'set'对象不可调用"

我有两个iPython笔记本电脑安装.一个在AWS Micro Instance上,第二个在我的Macbook上使用Anaconda(OS X Yosemite).我遇到两种处理以下代码的方式有所不同:

my_list = [1, 2, 3, 0, 5, 10, 11, 1, 5]
your_list = [1, 2, 3, 0, 12, 13]
my_set = set(my_list)
your_set = set(your_list)
print my_set
print len(my_set)
print len(my_list)
Run Code Online (Sandbox Code Playgroud)

在iPython-AWS上,我的输出是:

set([0, 1, 2, 3, 5, 10, 11])
7
9
Run Code Online (Sandbox Code Playgroud)

在iPython-Macbook上,我的输出是:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-29-cd060f1b0bde> in <module>()
      1 my_list = [1, 2, 3, 0, 5, 10, 11, 1, 5]
      2 your_list = [1, 2, 3, 0, 12, 13]
----> 3 …
Run Code Online (Sandbox Code Playgroud)

python macos ipython typeerror amazon-web-services

2
推荐指数
1
解决办法
2万
查看次数

遍历标记时出现“ ValueError:无法识别的标记样式-d”

我正在尝试对pyplot允许不同标记样式的绘图进行编码。这些图是循环生成的。从列表中选择标记。为了演示起见,我还列出了颜色列表。该版本是Python 2.7.9,IPython 3.0.0,matplotlib 1.4.3.

这是一个简单的代码示例:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

x=np.arange(0,10)
y=x**2

markers=['d','-d','-']
colors=['red', 'green', 'blue']

for i in range(len(markers)):
    plt.plot(x, y, marker=markers[i], color=colors[i])
    plt.show()
Run Code Online (Sandbox Code Playgroud)

这样就只能生成marker ='d'的图,因为'-d'它会返回错误:

...
C:\Users\batman\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\markers.pyc in set_marker(self, marker)
    245                 self._marker_function = self._set_vertices
    246             except ValueError:
--> 247                 raise ValueError('Unrecognized marker style {}'.format(marker))
    248 
    249         self._marker = marker

ValueError: Unrecognized marker style -d
Run Code Online (Sandbox Code Playgroud)

但是,我可以改为编写它plt.plot(x, y, markers[i], color=colors[i])。在color=...比较工作。

我认为这与特殊字符有关。我试过其他标记:这些标记 …

python matplotlib ipython anaconda

2
推荐指数
1
解决办法
5081
查看次数

没有名为html2text的模块

我已经尝试了各种方法来安装库html2text,所有这些都是因为ipython无法导入它并显示错误消息

"ImportError:没有名为html2text的模块"

The directory '/Users/NDunn/Library/Caches/pip/http' or its parent  directory is not
 owned by the current user and the cache has been disabled.
 Please check the permissions and owner of that directory.
 If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/NDunn/Library/Caches/pip/http' or its parent directory is not owned
by the current user and the cache has been disabled.
Please check the permissions and owner of that directory.
If executing pip with sudo, you may want sudo's …
Run Code Online (Sandbox Code Playgroud)

python ipython

2
推荐指数
1
解决办法
6307
查看次数

在IPython Notebook中显示决策树

我的目标是在IPython笔记本中显示决策树.我的问题是,当我尝试渲染它时,它打开一个新窗口,而我希望它是内联的(如matplotlib图).

这是我使用的代码:

def show_tree(decisionTree, out_file, feature_names):
    out_file = 'viz_tree/' + out_file
    export_graphviz(decisionTree, out_file=out_file, feature_names=feature_names)
    dot = ''
    with open(out_file, 'r') as file:
        for line in file:
            dot += line
    dot = Source(dot)
    return dot

decisionTree.fit(inputs, outputs)
d = show_tree(decisionTree, 'tree.dot', col_names)
d.render(view=True)
Run Code Online (Sandbox Code Playgroud)

我知道因为这个例子可以这样做.

你知道我怎么能这样做吗?

python graphviz ipython decision-tree ipython-notebook

2
推荐指数
1
解决办法
5777
查看次数

运行IPyhon.widgets时没有名为"ipywidgets"的模块错误

我安装了IPython 4.0.1.我无法弄清楚以下错误的原因 -

>>> from IPython.html import widgets
>>> k = widgets.Box
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\IPython\utils\shimmodule.py", line 90, in __getattr__
    return import_item(name)
  File "C:\Python34\lib\site-packages\IPython\utils\importstring.py", line 31, in import_item
    module = __import__(package, fromlist=[obj])
ImportError: No module named 'ipywidgets'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    k = widgets.Box
  File "C:\Python34\lib\site-packages\IPython\utils\shimmodule.py", line 92, in __getattr__
    raise AttributeError(key)
AttributeError: Box
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

python ipython ipython-notebook

2
推荐指数
2
解决办法
7523
查看次数

如何在jupyter中定义自定义魔法?

我正在使用Ubuntu 14.04 LTSAnaconda python安装:

Python 3.5.1 :: Anaconda 2.4.1(64位)

我正在尝试使用此配方在我的ipython笔记本中启用C++交互式编译:

import IPython.core.magic as ipym

@ipym.magics_class
class CppMagics(ipym.Magics):
    @ipym.cell_magic
    def cpp(self, line, cell=None):
        """Compile, execute C++ code, and return the standard output."""
        # Define the source and executable filenames.
        source_filename = 'temp.cpp'
        program_filename = 'temp.exe'
        # Write the code contained in the cell to the C++ file.
        with open(source_filename, 'w') as f:
            f.write(cell)
        # Compile the C++ code into an executable.
        compile = self.shell.getoutput("g++ {0:s} -o {1:s}".format( …
Run Code Online (Sandbox Code Playgroud)

python ipython ipython-notebook ipython-magic jupyter-notebook

2
推荐指数
1
解决办法
1854
查看次数

在现有笔记本服务器上打开ipython笔记本

我正在寻找一种在现有笔记本电脑服务器上打开ipynb文件的方法.

我的主目录上有一个笔记本服务器,如下所示:

/home/myname$ ipython notebook
Run Code Online (Sandbox Code Playgroud)

我有一个笔记本文件/home/myname/work_dir/test.ipynb.我需要一个脚本在笔记本上打开这个文件:

cd work_dir
ipynb_open test.ipynb  # No such command!
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过以下命令在新的笔记本服务器上打开此ipynb:

ipython notebook test.ipynb
Run Code Online (Sandbox Code Playgroud)

但是这个命令是一个新服务器,我必须手动杀死这个服务器.

在这种情况下,由于我知道执行笔记本的目录,我可以test.ipynb通过直接指定其相对路径来打开:

open http://localhost:8888/node/work_dir/test.ipynb
Run Code Online (Sandbox Code Playgroud)

但我想自动解决此地址.

阅读文档,我找到了一个选项--existing,但是以下命令不起作用.

ipython notebook --exsiting test.ipynb
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:

  • 是否有与ipynb_open上述相对应的命令?
  • 有没有办法收集有关运行笔记本电脑服务器的信息?

python ipython jupyter-notebook

2
推荐指数
1
解决办法
760
查看次数

Ipython笔记本,如何设置正确的内核路径

在Windows 7 64bit上运行ipyhton笔记本并使用python 2内核启动笔记本时出现错误:

Traceback (most recent call last):
  File "C:\Users\USER1\Anaconda2\lib\site-packages\notebook\base\handlers.py", line 436, in wrapper
    result = yield gen.maybe_future(method(self, *args, **kwargs))
  File "C:\Users\USER1\Anaconda2\lib\site-packages\notebook\services\sessions\handlers.py", line 56, in post
    model = sm.create_session(path=path, kernel_name=kernel_name)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 66, in create_session
    kernel_name=kernel_name)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 84, in start_kernel
    **kwargs)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\jupyter_client\multikernelmanager.py", line 109, in start_kernel
    km.start_kernel(**kwargs)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 244, in start_kernel
    **kw)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 190, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "C:\Users\USER1\Anaconda2\lib\site-packages\jupyter_client\launcher.py", line 115, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "C:\Users\USER1\Anaconda2\lib\subprocess.py", …
Run Code Online (Sandbox Code Playgroud)

path ipython anaconda jupyter jupyter-notebook

2
推荐指数
1
解决办法
6430
查看次数

是否有可能改变IPython的漂亮打印机?

是否有可能改变IPython使用的漂亮的打印机?

我想切换默认的漂亮的打印机pprint++,我更喜欢嵌套结构之类的东西:

In [42]: {"foo": [{"bar": 42}, {"bar": 16}] * 3, "bar": [1,2,3,4,5]}
Out[42]: 
{'bar': [1, 2, 3, 4, 5],
 'foo': [{'bar': 42},
  {'bar': 16},
  {'bar': 42},
  {'bar': 16},
  {'bar': 42},
  {'bar': 16}]}

In [43]: pprintpp.pprint({"foo": [{"bar": 42}, {"bar": 16}] * 5, "bar": [1,2,3,4,5]})
{
    'bar': [1, 2, 3, 4, 5],
    'foo': [
        {'bar': 42},
        {'bar': 16},
        {'bar': 42},
        {'bar': 16},
        {'bar': 42},
        {'bar': 16},
        {'bar': 42},
        {'bar': 16},
        {'bar': 42},
        {'bar': 16},
    ],
}
Run Code Online (Sandbox Code Playgroud)

python ipython pprint

2
推荐指数
1
解决办法
157
查看次数

重置IPython内核而无需重新启动

有没有一种方法可以通过编程方式重置IPython内核而无需重新启动它?

目前我正在打电话,KernelManager.restart_kernel但是那很慢。

这样做的目的是隔离py.test插件中的单元测试,以将Notebook单元用作单元测试。如果您有其他想法可以实现这一点,我会建议您。代码在这里:

https://github.com/zonca/pytest-ipynb/blob/master/pytest_ipynb/plugin.py#L100

ipython jupyter-notebook

2
推荐指数
1
解决办法
5288
查看次数