如何在每次执行python时导入模块?
每次运行python时,我都需要运行命令如何在每次执行python时导入模块?,python,Python,每次运行python时,我都需要运行命令importnumpyasnp。如何在linux中实现自动化。换句话说,在每次启动python时,如何手动调用模块?标记-i可以帮助您完成这一任务。请参见manpython -i When a script is passed as first argument or the -c option is used, enter interactive mode after executing the
importnumpyasnp
。如何在linux中实现自动化。换句话说,在每次启动python时,如何手动调用模块?标记-i
可以帮助您完成这一任务。请参见manpython
-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.
下面的内容就是你想要的。请注意,-i
标志必须位于-c
之前,否则它将不起作用
python -i -c 'import numpy'
-i
标志可以帮助实现这一点。请参见manpython
-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.
下面的内容就是你想要的。请注意,-i
标志必须位于-c
之前,否则它将不起作用
python -i -c 'import numpy'
实际上,更好的方法是创建一个包含
import numpy as np
的文件,并将其名称分配给PYTHONSTARTUP,最好是在.bashrc或通过启动shell执行的任何其他shell脚本中(取决于所使用的shell)。实际上,更好的方法是创建一个包含import numpy as np
的文件,并将其名称分配给PYTHONSTARTUP-最好是在.bashrc或通过启动shell(取决于所使用的shell)执行的任何其他shell脚本中。