Preload Some Libraries And Scripts In Python
How to preload some libraries and scripts in python before I call python command? Is there something like .bashrc file to deal with predefining some functions/variables before laun
Solution 1:
How about this:
python -i -c "import math"
And you can put this into a bash file, like b.sh
#! /bin/bash
python -i -c "import math"
Then you can set whatever you want.
Solution 2:
i wanted to sometimes run python with a bunch of statistics/math stuff loaded (numpy, matplotlib, etc), but othertimes just a simple python without having the overhead of loading modules i wasn't going to use.
i use ubuntu linux, so i created a python script python-preload.py
with the following:
import numpy as np
import matplotlib.pyplotas plt
import matplotlib as mpl
and added an alias to my ~/.bashrc
:
alias pym='PYTHONSTARTUP=/home/$USER/path/to/script/python-preload.py python'
so when i want normal python i run python
, and when i want all the math stuff i run pym
.
hope this helps. based off Tony Blundell's answer.
Post a Comment for "Preload Some Libraries And Scripts In Python"