RobMSN
RobMSN

Reputation: 87

Load iPython with custom packages imported

Does anyone know if it is possible to load ipython preloaded with custom packages please?

I'm running Python 2.7 on Windows 8.

When I load a DOS prompt, I run ipython preloaded with pylab by typing

ipython --pylab

I've managed to create a shortcut to open a DOS prompt with this automatically fired, thus effectively creating a shortcut to iPython.

However, I'd like iPython to start preloaded with some of my custom packages. So I wonder if there is a way to start iPython and automatically execute the following lines, say:

import package1 as my_package
import package2 as my_second_package

I've had a look online and there's some information on "magic" commands and scripts in iPython which looks like it might help, although I wasn't sure how to use this.

All guidance welcomed.

Many thanks.

Upvotes: 6

Views: 2873

Answers (2)

Jiehong
Jiehong

Reputation: 885

If you have a look at the documentation, you will find out that IPython will run whatever is inside the file pointed by the PYTHONSTARTUP variable.

Create one, export the variable, and there you go.

References:

Upvotes: 1

Thomas K
Thomas K

Reputation: 40390

What you want is a startup script.

First run ipython locate profile to find the profile folder. Then find a startup folder in there. Create a .py file (any name) in the startup folder with the imports you want, and IPython will run that whenever you it starts.

Upvotes: 9

Related Questions