简体   繁体   English

如何为 ipython 创建项目特定的启动脚本

[英]How to create a project specific startup script for ipython

我能够找到很多关于如何在“IPYTHONDIR”中提供配置文件的文档,但我希望将所有与项目相关的文件都放在项目目录中,这样我的 ipython 配置就在同一个 git repo 中管理与其他用户共享项目时不需要额外的步骤。

The best way to do this would be to create a .ipython directory in your project directory.最好的方法是在你的项目目录中创建一个.ipython目录。 You can do this as:你可以这样做:

$ mkdir /path/to/project/.ipython

You should then generate default configuration files in this directory as:然后,您应该在此目录中生成默认配置文件:

$ ipython profile create my_config_name --ipython-dir /path/to/project/.ipython

Now you can edit these default config files as you desire for this project.现在,您可以根据需要为该项目编辑这些默认配置文件。

Then, we'll need to instruct iPython on where to look to find these config files.然后,我们需要指示 iPython 去哪里寻找这些配置文件。 To do so we will alter the IPYTHONDIR environment variable.为此,我们将更改IPYTHONDIR环境变量。 This is as simple as:这很简单:

$ export IPYTHONDIR=/path/to/project/.ipython

With this, iPython will now use the configuration files you've set for this project.有了这个,iPython 现在将使用您为此项目设置的配置文件。

If you're sharing the project with other users you could always put the above export command in a little shell script, say, set_ipy.sh , to make things even easier.如果您要与其他用户共享该项目,您始终可以将上述导出命令放在一个小的 shell 脚本中,例如set_ipy.sh ,以使事情变得更容易。 Just ensure that the script is sourced ( source set_ipy.sh ) and not run as ./set_ipy.sh , otherwise the IPYTHONDIR environment variable will not be altered for the current shell.只需确保脚本来源( source set_ipy.sh )并且不作为./set_ipy.sh运行,否则IPYTHONDIR环境变量不会为当前 shell 更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM