Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在每次执行python时导入模块?_Python - Fatal编程技术网

如何在每次执行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

每次运行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  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脚本中。