NameError:未定义名称“get_ipython” [英] NameError: name 'get_ipython' is not defined

查看:616
本文介绍了NameError:未定义名称“get_ipython”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Caffe框架并使用PyCaffe接口。我正在使用从转换IPython Notebook 00-classification.ipynb 获得的Python脚本,以便通过训练有素的ImageNet模型测试分类。但是脚本中的任何 get_ipython()语句都会出现以下错误:

I am working on Caffe framework and using PyCaffe interface. I am using a Python script obtained from converting the IPython Notebook 00-classification.ipynb for testing the classification by a trained model for ImageNet. But any get_ipython() statement in the script is giving the following error:

$ python python/my_test_imagenet.py 
Traceback (most recent call last):
  File "python/my_test_imagenet.py", line 23, in <module>
    get_ipython().magic(u'matplotlib inline')

在脚本中,我导入以下内容:

In the script, I'm importing the following:

import numpy as np
import matplotlib.pyplot as plt

get_ipython().magic(u'matplotlib inline')

# Make sure that caffe is on the python path:
caffe_root = '/path/to/caffe/'
import sys
sys.path.insert(0, caffe_root + 'python')

import caffe

plt.rcParams['figure.figsize'] = (10, 10)
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'

import os

# ... Rest of the code...

有人可以帮我解决这个错误吗?

Can someone please help me to resolve this error?

推荐答案

你必须用ipython运行你的脚本:

You have to run your script with ipython:

$ ipython python/my_test_imagenet.py

然后 get_ipython 将b e已经在全球范围内。

Then get_ipython will be already in global context.

注意:通过从普通shell中的IPython import get_ipython 导入 python 将无法正常工作 ipython 正在运行。

Note: Importing it via from IPython import get_ipython in ordinary shell python will not work as you really need ipython running.

这篇关于NameError:未定义名称“get_ipython”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆