preload some libraries and scripts in python

后端 未结 3 464
悲哀的现实
悲哀的现实 2021-01-18 18:46

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 befo

3条回答
  •  无人及你
    2021-01-18 19:04

    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.pyplot as 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.

提交回复
热议问题