问题描述
我试图在Windows 7 64位计算机上的 IPython
启动时从__future__ import division 加载之类的内容,
python 2.7 64位
。
I am trying to load things like
from __future__ import division
on the IPython
startup on windows 7 64 bit machine, python 2.7 64 bit
.
我搜索了网页,我发现推荐的方法是放
.py
文件,说明如下: C:\ Users \ Me\.ipython\profile_default\startup
。我从__future__ import输入了一个简单的 .py
文件,其中包含
I searched the web and the recommended way I found is to put a
.py
file with instructions in: C:\Users\Me\.ipython\profile_default\startup
. I've put a simple .py
file containing
from __future__ import division
from __future__ import unicode_literals
在该文件夹中。但它实际上什么也没做。更令人困惑的是文件似乎执行,因为如果我在那里放一些随机错误行,我看到Ipython启动时出错。仍然没有导入除法,必须重新导入它,从shell中的__future__ import division
输入。
in that folder. But it actually does nothing. What is more confusing is that the file seems to execute, because if I put some random error line in there, i see an error on Ipython start. Still division is not imported and have to re-import it typing
from __future__ import division
in the shell.
I在
Anaconda
和 Winpython
上尝试了它( IPython的设置
在这个分布上是在其他文件夹中)具有相同的结果。我重新导入后一切正常。完全停留在这里,请帮助!
I tried it both on
Anaconda
and Winpython
(settings for IPython
on this distribution are in other folder) with the same result. After I re-import everything works fine. Totally stuck here, please help!
推荐答案
检查
C:\ Users \ Me \.ipython\profile_default\ipython_config.py
存在。如果没有,请运行
Check to see if
C:\Users\Me\.ipython\profile_default\ipython_config.py
exists. If it doesn't, run
ipython profile create
从命令行生成它。接下来,在您喜欢的文本编辑器中打开它,然后搜索
c.InteractiveShellApp.exec_lines
。取消注释该行(它是我文件中的第27行)并将其编辑为以下内容:
from the command line to generate it. Next, open it in your favorite text editor and search for
c.InteractiveShellApp.exec_lines
. Uncomment that line (it's line 27 in my file) and edit it to be the following:
c.InteractiveShellApp.exec_lines = ["from __future__ import division", "from __future__ import unicode_literals"]
保存文件,重新启动IPython,你应该全部设置。
Save the file, restart IPython, and you should be all set.
这篇关于IPython启动定制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!