https://stackoverflow.com/questions/11124578/automatically-import-modules-when-entering-the-python-or-ipython-interpreter
https://stackoverflow.com/questions/52512650/python-path-and-juptyter-notebook-on-windows
https://stackoverflow.com/a/11124846/19253199
首先找到ipython_config.py文件
ipython profile create
如果已经有了就用下面的定位
ipython profile locate
然后增加这一行
c.InteractiveShellApp.exec_lines = ['import numpy as np', 'print("import numpy as np")']
结果
更多请看ipython_config的用法请看
https://ipython.readthedocs.io/en/stable/config/intro.html#example-configuration-file
方法2:启动脚本放startup文件夹里
ipython profile locate找到文件夹。里面有个profile_default,再往里面有个startup文件夹。把脚本放这里
import numpy as np
import scipy, os, sys
from scipy.io import mmread, mmwrite
print("Using startup.py at ", __file__)
print("import numpy, scipy and mmread, mmwrite")
os.chdir("E:/Dev/tiPBD/")
sys.path.append(os.getcwd())
print("Current working directory is:", os.getcwd())