问题标签 [ipython]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
851 浏览

python - 谷歌应用引擎、Python 和 IPython

我想在GAE下使用IPython在本地调试脚本:

但 GAE 限制从 sys.path 加载一些模块。我可以以某种方式绕过这个吗?

0 投票
2 回答
2278 浏览

python - Python shell 和 execfile 范围

我在 ipython shell 内部工作,并且经常需要重新加载包含我正在构建的函数的脚本文件。

在我的 main.py 中,我有:

def myreload(): execfile("main.py") execfile("otherfile.py")

如果我已经在同一个 ipython 会话中直接运行了 execfile 命令,则调用 myreload() 可以正常工作。

但是,由于某种原因,如果会话是新的并且我只是调用了 execfile("main.py"),那么 myreload() 实际上不会使 otherfile.py 中的函数可用。虽然它不会抛出任何错误。

有任何想法吗?

0 投票
2 回答
3963 浏览

shell - ipython shell awk:转义“$”符号

我正在弄清楚 Ipython shell 支持。它似乎 awk 不起作用,即遵循命令

只打印“1”。

如何将“$”符号正确传递给 shell。我正在使用 zsh。

0 投票
2 回答
829 浏览

python - Python:快速将 7 GB 的文本文件加载到 unicode 字符串中

我有一个很大的文本文件目录——大约 7 GB。我需要将它们快速加载到 iPython 中的 Python unicode 字符串中。我总共有 15 GB 的内存。(我使用的是 EC2,所以如果绝对必要,我可以购买更多内存。)

对于我的目的来说,简单地阅读文件太慢了。我尝试将文件复制到 ramdisk,然后将它们从那里加载到 iPython 中。这加快了速度,但 iPython 崩溃(没有足够的内存剩余?)这是 ramdisk 设置:

有人有想法么?基本上,我正在寻找持久的内存中 Python 对象。iPython 要求禁止使用 IncPy: http: //www.stanford.edu/~pgbovine/incpy.html

谢谢!

0 投票
1 回答
821 浏览

python - 如何在eclipse中暂停python执行并返回交互式提示

我使用 Eclipse 作为 Python IDE。无论如何我可以调试我的程序并中断到交互式提示。我有兴趣探索现有数据和运行/测试命令。

我相信必须有一种方法,但我已经习惯了编译语言,以至于我无法找到选项在哪里。

有任何想法吗?

0 投票
2 回答
2994 浏览

python - 模棱两可的制表符完成在 Windows 上的 iPython 中不起作用

我在安装了 pyreadline 的 Windows 7 x64 上运行 IPython。如果我开始一个新会话并输入:

然后nu自动完成到numpy. 但是,如果我开始一个新会话并尝试以下操作:

然后什么也没有发生。我希望它循环遍历所有可能的完成。我目前正在使用开箱即用的配置,是否需要更改设置以启用模棱两可的选项卡完成,或者我只是不走运?

编辑:为了解决来自 ma3204 的评论,这是另一个示例(从新的 ipython 会话开始):

当我va<TAB>在上面输入时,我希望每个选项卡按下都会循环显示value1, value2, vars, value1,value2等。

0 投票
11 回答
50492 浏览

python - 如何在 django shell 中重新加载模块?

我正在使用 Django 并一直使用 Django shell。烦人的部分是,当 Django 服务器重新加载代码更改时,shell 不会,所以每次我对正在测试的方法进行更改时,我都需要退出 shell 并重新启动它,重新导入我的所有模块需要,重新初始化我需要的所有变量等。虽然 iPython 历史在这方面节省了很多打字,但这仍然很痛苦。有没有办法让 django shell 自动重新加载,就像 django 开发服务器一样?

我知道 reload(),但是我导入了很多模型并且通常使用from app.models import *语法,所以 reload() 并没有太大帮助。

0 投票
1 回答
912 浏览

python - 如何配置 ipy_user_conf.py 以使 IPython 以正确的 IDLE 设置为编辑器开始?

64 位 Vista Python 2.6 IPython 0.10 还有 Python 2.7 和 3.1

我的 ipy_user_conf.py 有显示如何设置编辑器的示例行。我试过了

ipy_editors.idle()

[C:Python26/脚本] |4>ed xxx.py 正在编辑...> C:\Python26\lib\idlelib/idle.py "xxx.py"

打开 Python 3.1 的 IDLE,并且不打开 xxx.py。

我接下来在 ipy_user_conf.py 中模仿了一个示例行,

ipy_editors.scite('c:/opt/scite/scite.exe')

作为

ipy_editors.idle("c:/Python26/Lib/idlelib/idle.pyw")

[C:Python26/Scripts] |4>ed xxx.py 编辑... > c:/Python26/Lib/idlelib/idle.pyw "xxx.py"

在 IDLE for Python 3.1 中打开文件 c:/Python26/Lib/idlelib/idle.pyw

我已经没有想法了。建议,请。

顺便说一句,运行 xxx.py 工作正常。

0 投票
1 回答
1046 浏览

logging - 如何配置 ipy_user_conf.py 让 IPython 立即开始记录?

64 位 Vista、Python 2.6、IPython 0.10

我想尝试记录我所做的一切,所以我设置

o.log = 1

在我的 ipy_user_conf.py 中。

但是记录没有开始。如果我在提示符下输入“logstart”,它会。但是'o.log = 1'有什么问题?

0 投票
1 回答
1230 浏览

python - 请帮助:Windows 上用于 Emacs 的 IPython 崩溃

问题更新:为什么没有 In[1]: 提示?

请参阅 Emacs 中 IPython 命令行的以下输出。


你好,

我在 Windows XP 上使用 IPython 0.10、Python 2.5 和 EmacsW32 23.1 和 ipython.el Rev.2927。当我在 Emacs 中调用 python-shell 时,它总是崩溃。有人可以帮助解决这个问题吗?非常感谢!

更新:我已经尝试修复https://bugs.launchpad.net/ipython/+bug/290228,但它没有帮助。

IPython 崩溃并显示以下长调试信息:

错误:标记输入时发生意外错误以下回溯可能已损坏或无效错误消息是:('EOF in multi-line statement', (14, 0))

-------------------------------------------------- ------------------------- TypeError
Python 2.5.2: C: \Python25\python.exe Thu Sep 30 14:00:08 2010 一个问题发生执行 Python 代码。这是导致错误的函数调用序列,最近的(最里面的)调用最后。

c:\Python25\Scripts\ipython-script.py in () 1 2 3 4 5 6 7 ----> 8 global load_entry_point = 9 #!C:\Python25\python.exe 10 # EASY-INSTALL-ENTRY-脚本: 'ipython==0.10','console_scripts','ipython' 11需要= 'ipython==0.10' 12 从 pkg_resources 导入 sys 13 import load_entry_point 14 15 sys.exit( 16 load_entry_point('ipython==0.10', '控制台脚本','ipython')()17)18 19 20 21 22 23 24 25 26 27 28 29 30 31

562 563 这构建了一个字典,其中包含作为 564 有效 IPython 用户命名空间运行所需的最少信息,您可以将其传递给 ipython 中的各种嵌入 565 类。566 567 此 API 目前已弃用。使用 ipapi.make_user_namespaces() 而不是 568 同时创建本地和全局命名空间对象。569 570:参数:571 user_ns:类似字典,可选 562 563 这构建了一个字典,其中包含作为 564 有效 IPython 用户命名空间运行所需的最少信息,您可以将其传递给 ipython 中的各种嵌入 565 类。566 567 此 API 目前已弃用。使用 ipapi.make_user_namespaces() 而不是 568 同时创建本地和全局命名空间对象。569 570:参数:571 user_ns:类似字典,可选

C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\ipapi.pyc in make_session(user_ns=None, shellclass=None) 669 670 def make_session(user_ns = None, shellclass = None) : 671 """ 生成,但不启动 IPython 会话。672 673 稍后您可以在返回的对象上调用 obj.mainloop()。674 675 输入:676 677 - user_ns(None):用作具有初始 678 数据的用户命名空间。679 680 警告:这不应该当会话已经存在时运行。""" 681 682 import IPython.Shell 683 if shellclass is None: --> 684 return IPython.Shell.start(user_ns) 685 return shellclass(user_ns = user_ns) 686 687 688 689 690 691 692 693 694 695 696 697 698 699

C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\Shell.pyc in start(user_ns=None) 1226
th_mode = special_opts.pop() 1227
除了 KeyError: 1228
th_mode = 'tkthread ' 1229
return th_shell[th_mode] 1230
1231 1232 # 这个应该是外部代码调用的那个。
1233 def start(user_ns = None):
1234 """返回一个正在运行的 shell 实例,处理线程选项。 1235 1236 这是一个工厂函数,它将
根据用户的线程选择实例化正确的 IPython shell 1237。这样的选择器是需要,因为 1238 个不同的 GUI 工具包需要不同的线程处理细节。""" 1239 1240
shell = _select_shell(sys.argv) -> 1241 return shell(user_ns = user_ns) 1242 1243 # 向后兼容的一些别名
1244 IPythonShell = IPShell 1245 IPythonShellEmbed = IPShellEmbed
1246 # * ** * ** * ** * ** End of文件 * ** * ** * ** * ** * 1247 1248 1249 1250 1251 1252
1253 1254 1255 1256

C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\Shell.pyc in init (self=, argv=None, user_ns=None, user_global_ns=None, debug=1, shell_class= ) 58 # 等待多线程 shell 的默认超时时间(以秒为单位) 59 GUI_TIMEOUT = 10 60 61

-------------------------------------------------- --------------------------

干净的63#接口。稍后当内部结构重新组织时,使用这个 64 # 的代码不应该改变。65 66 class IPShell: 67 """创建一个 IPython 实例。""" 68 69 def init(self,argv=None,user_ns=None,user_global_ns=None, 70 debug=1,shell_class=InteractiveShell): 71 self.IP = make_IPython(argv,user_ns=user_ns, 72 user_global_ns=user_global_ns, ---> 73 debug= debug,shell_class=shell_class) global that = undefined global gets = undefined global prepend = undefined global to = undefined global all = undefined global calls = undefined global so = undefined global header = undefined global used = undefined 74 75 def mainloop(self,sys_exit =0,banner=None): 76 self.IP.mainloop(banner) 77 if sys_exit: 78 sys.exit() 79 80

-------------------------------------------------- --------------------------

嵌入式 IPython。83 84 这个函数(在请求确认后)设置一个内部标志,这样 85 嵌入式 IPython 将永远不会再次激活。这对于 86 永久禁用在循环中调用的 shell 很有用:一旦你 87 弄清楚你需要什么,你就可以杀死它,然后程序 88 将继续运行,而交互式 shell 不会再次干扰.

C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\ipmaker.pyc in make_IPython(argv=[r'c:\Python25\Scripts\ipython-script.py', '- i'], user_ns=None, user_global_ns=None, debug=1, rc_override=None, shell_class=, embedded=False,kw={}) 755 IP_rc.banner = 0 756 if IP_rc.banner: 757 BANN_P = IP.BANNER_PARTS 758 else: 759 BANN_P = [] 760 761 if IP_rc.profile: BANN_P.append('IPython profile: %s\n ' % IP_rc.profile) 762 763 # 添加消息日志(可能为空) 764 if msg.summary: BANN_P.append(msg.summary) 765 # 最终横幅是字符串 766 IP.BANNER = '\n'.join(BANN_P ) 767 768 # 完成 IPython 实例。这假设 rc 结构已完全到位 769 #。--> 770 IP.post_config_initialization() 771 772 return IP 773 # * ** * ** * ** * ****文件结束


C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\iplib.pyc in post_config_initialization(self=) 847 配置文件处理完成后调用 848 'finalize' 初始化.""" 849 850 rc = self.rc 851 852 # 对象检查器 853 self.inspector = OInspect.Inspector(OInspect.InspectColors, 854 PyColorize.ANSICodeColors, 855 'NoColor', 856 rc.object_info_string_level) 857 858 self.rl_next_input =无 859 self.rl_do_indent = False 860 # 正确加载 readline 861 if rc.readline: --> 862 self.init_readline() 863 864 # 本地快捷方式,这是一个 LOT 865 self.log = self.logger.log 866 867 # 初始化缓存,设置输入/输出提示和打印系统 868 self.outputcache = CachedOutput(self, 869 rc.cache_size, 870 rc.pprint, 871 input_sep = rc.separate_in, 872 output_sep = rc.separate_out, 873 output_sep2 = rc.separate_out2, 874 ps1 = rc.prompt_in1, 875 ps2 = rc.prompt_in2, 876 ps_out = rc.prompt_out, 877 pad_left = rc。prompts_pad_left)

C:\Python25\lib\site-packages\ipython-0.10-py2.5.egg\IPython\iplib.pyc init_readline(self=) 1476
if not readline.uses_libedit: 1477 for rlcommand in self.rc.readline_parse_and_bind:
1478 #print "loading rl:",rlcommand # dbg 1479 readline.parse_and_bind(rlcommand)
1480 1481 # 从分隔符列表中删除一些字符。如果我们遇到 1482 # unicode 字符,丢弃它们。第1483
章 delims = readline.get_completer_delims().encode(“ascii”,“忽略”)1484 delims = delims.translate(string._idmap,
1485 self.rc.readline_remove_delims)
1486
readline.set_completer_delims(delims) 1487 # 否则我们会在一段时间后得到一个怪物历史:1488
readline.set_history_length(1000)
1489 try: 1490

print ' *读取 readline 历史记录' # dbg

-> 1491 readline.read_history_file(self.histfile) 1492 除了 IOError:
1493 pass # 它还不存在。1494 1495
atexit.register(self.atexit_operations) 1496 del atexit 1497
1498 # 为所有平台配置自动缩进 1499
self.set_autoindent(self.rc.autoindent) 1500 1501 def ask_yes_no(self,prompt,default=True): 1502 if self.rc.quiet: 1503 返回 True 1504 返回 ask_yes_no(prompt,default) 1505
1506 def new_main_mod(self,ns=None):

C:\Python25\lib\site-packages\pyreadline\rlmain.pyc in read_history_file(self=, filename=u'C:\Home\_ipython\history') 168 169 def set_history_length(self, length): 170 '''设置要保存在历史文件中的行数。171 172 write_history_file() 在保存时使用该值截断历史文件 173。负值意味着无限的历史文件大小。174 ''' 175 self._history.set_history_length(length) 176 177 def clear_history(self): 178 '''清除读行历史记录''' 179 self._history.clear_history() 180 181 def read_history_file(self, filename=None) : 182 '''加载一个 readline 历史文件。默认文件名是~/.history.''' --> 183 self._history.read_history_file(filename) 184 185 def write_history_file(self, filename=None): 186 '''保存一个readline历史文件。默认文件名是~/.history.''' 187 self._history.write_history_file(filename) 188 189 #Completer functions 190 191 def set_completer(self, function=None): 192 '''设置或移除完成函数。193 194 如果指定了函数,它将作为新的完成者 195 函数;如果省略或无,则删除已安装 196 的任何完成函数。完成者函数称为 197 函数(文本,状态),用于状态 0、1、2、.. ., 直到它返回一个 198 非字符串值。它应该返回下一个可能的完成

C:\Python25\lib\site-packages\pyreadline\lineeditor\history.pyc in read_history_file(self=, filename=u'C:\Home\_ipython\history') 55 56 history_length=property(get_history_length,set_history_length) 57 history_cursor =property(get_history_cursor,set_history_cursor) 58 59 def clear_history(self): 60 '''清除 readline 历史记录。''' 61 self.history[:] = [] 62 self.history_cursor = 0 63 64 def read_history_file(self, filename =None): 65 '''加载一个 readline 历史文件。''' 66 如果文件名是 None: 67 filename=self.history_filename 68 try: 69 for line in open(filename, 'r'): ---> 70自己。add_history(lineobj.ReadLineTextBuffer(ensure_unicode(line.rstrip()))) 全局 n = 未定义的全局 Xd = 未定义的全局 S = 未定义的全局 NR = 未定义的全局 i = 未定义的全局 R2 = 未定义的全局 R = 未定义的全局 t = 未定义的全局 history_search_forwardt = 未定义的全局 history_search_backwardt = 未定义的全局 joinR2 = 未定义global maxR = undefined global mint = undefined global IndexError = undefined global RX = undefined global partialt = undefined global hcstartt = undefined global hct = undefined global ht = undefined global result = undefined global s = undefined global C = undefined global Python25 = undefined global lib = 未定义全局站点 = 未定义的全局包 = 未定义的全局 pyreadline = 全局 lineeditor = 未定义的全局 history.pyt = 未定义的全局search = undefined global I = undefined global c = undefined global d = undefined global search = undefined global forward = undefined global through = undefined global the = undefined global history = undefined global string = global of = undefined global characters = undefined global between = undefined global start = undefined global current = undefined line = 'import sys\n' global point.this = undefined global a = undefined global non = undefined global incremental = undefined global search.By = undefined global default = undefined global this = undefined global command = 未定义的全局未绑定。i = 未定义的全局 Rj = 未定义的全局 Re = 未定义的全局 q = 未定义的全局 history.pyR= 未定义的全局后向 = 未定义的全局 Rk = 未定义的全局 history.pyR = 未定义的全局 N = 未定义的全局属性 R = 未定义的全局 R4 = 未定义的全局 R5 = 未定义的全局 R7 = 未定义的全局 R8 = 未定义的全局 RC = 未定义的全局 RD = 未定义的全局 R_ = 未定义的全局 st = 未定义

按回车退出:global_main_t = undefined global aaaat = undefined global aabat = undefined global aacat = undefined global akcat = undefined global bbbt = undefined global ako = undefined global ret = undefined global operatorRS = undefined global sysR = undefined global pyreadline.unicode_helperR = undefined global modulesR = undefined global exceptionst = undefined global ExceptionR = undefined global pyreadline.loggerR = undefined global FalseR9 = undefined global objectR = undefined global RLR = undefined global history.pys = undefined global module = undefined 71 except IOError: 72 self.history = [] 73 self.history_cursor = 0 74 75 def write_history_file(self, filename=None): 76 '''保存一个 readline 历史文件。''' 77 如果文件名是 None: 78 filename=self.history_filename 79 fp = open(filename, 'wb' ) 80 for line in self.history[-self.history_length:]: 81 fp.write(ensure_str(line.get_line_text())) 82 fp.write('\n') 83 fp.close() 84 85) 80 for line in self.history[-self.history_length:]: 81 fp.write(ensure_str(line.get_line_text())) 82 fp.write('\n') 83 fp.close() 84 85) 80 for line in self.history[-self.history_length:]: 81 fp.write(ensure_str(line.get_line_text())) 82 fp.write('\n') 83 fp.close() 84 85

C:\Python25\lib\site-packages\pyreadline\unicode_helper.pyc in ensure_unicode(text='import sys') 5 # 根据 BSD 许可条款分发。完整许可证在 6# 文件 COPYING 中,作为该软件的一部分分发。7

** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * *

ascii 代码页 15 16 17 def ensure_unicode(text): 18 """帮助确保传递给 WriteConsoleW 的文本是 unicode""" 19 if isinstance(text, str): ---> 20 return text.decode(pyreadline_codepage, " replace") 21 return text 22 23 def ensure_str(text): 24 """Convert unicode to str using pyreadline_codepage""" 25 if isinstance(text, unicode): 26 return text.encode(pyreadline_codepage, "replace") 27 return文字 28 29 30 31 32 33 34 35

TypeError: decode() 参数 1 必须是字符串,而不是 None


糟糕,IPython 崩溃了。我们尽最大努力使其稳定,但是...

使用以下信息自动生成崩溃报告: - 崩溃回溯的逐字副本。- 在此会话期间您的输入历史记录的副本。- 有关您当前 IPython 配置的数据。

它留在名为:'C:\Home_ipython\IPython_crash_report.txt'的文件中。如果您可以将此文件通过电子邮件发送给开发人员,其中的信息将帮助他们理解和纠正问题。

您可以将其邮寄给:Fperez 的 Fernando Perez....@gmail.com,主题为“IPython 崩溃报告”。

如果您现在想这样做,以下命令将起作用(在 Unix 下): mail -s 'IPython Crash Report' fperez....@gmail.com < C:\Home_ipython \IPython_crash_report.txt

为确保准确跟踪此问题,请在以下位置提交报告: https ://bugs.launchpad.net/ipython/+filebug