Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 456
RobMSN Avatar asked Jul 29 '13 02:07

RobMSN


People also ask

How do I import a package into IPython?

No more typing “import pandas as pd” 10 times a dayCreate a folder called startup if it's not already there. Add a new Python file called start.py. Put your favorite imports in this file. Launch IPython or a Jupyter Notebook and your favorite libraries will be automatically loaded every time!

How do you access a module imported from a package in Python?

Importing module from a package We can import modules from packages using the dot (.) operator. Now, if this module contains a function named select_difficulty() , we must use the full name to reference it. Now we can directly call this function.


1 Answers

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.

like image 94
Thomas K Avatar answered Sep 19 '22 23:09

Thomas K