0

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 1

2

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'
Sign up to request clarification or add additional context in comments.

1 Comment

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.