I need to run the command import numpy as np each time I run python. How to automatize it in linux. In other words, how do load a module each time python is launch with having to manually call it?
1 Answer
The -i flag can help with that. See man python.
-i When a script is passed as first argument or the -c option is
used, enter interactive mode after executing the script or the
command. It does not read the $PYTHONSTARTUP file. This can be
useful to inspect global variables or a stack trace when a script
raises an exception.
So the below does what you want it to. Note that the -i flag needs to precede the -c otherwise it doesn't work.
python -i -c 'import numpy'
1 Comment
Błotosmętek
Actually a better way would be to create a file containing
import numpy as np and assign its name to PYTHONSTARTUP - preferably in .bashrc or any other shell script that is executed by starting shell (depends on the shell being used).