I am on Windows 7. When I launch Python IDLE, I want it to pre-load: pandas
, numpy
and matplotlib
without me having to type out the import statements. I import them very frequently.
I have waded through several posts:
This one has to do with iPython, not IDLE-specific
This one has to do with running a script in IDLE
This one talks about PYTHONSTARTUP for interactive sessions
From these posts, I have determined that there is a distinct difference between Windows command-prompt python interactive shell and IDLE's interactive shell.
For example, I created defaultimports.py
and put it in this location:
C:\Python34\Lib\site-packages\jaradspythonstartup
That script contains the following:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
print('pd, np and plt imported')
Next, on my machine, I went to Start
> Computer
> right-clicked Properties
> Advanced system settings
> environment variables
> clicked New...
and added a new variable
named PYTHONSTARTUP
, then put my path
C:\Python34\Lib\site-packages\jaradspythonstartup\defaultimports.py
However, this seems to only work in Windows Command prompt when I open command prompt and type python
. I do see it loads my print statement.
When I launch IDLE, I don't see the message: pd, np, and plt imported
print statement. While in IDLE, if I import os
and os.environ['PYTHONSTARTUP']
, I do see my environment variable defined but don't know if that's important to note or not.
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import os
>>> os.environ['PYTHONSTARTUP']
'C:\\Python34\\Lib\\site-packages\\jaradspythonstartup\\defaultimports.py'
>>>
My Question
How can I pre-load modules in IDLE on startup?