start ipython notebook with python file

后端 未结 4 1255
既然无缘
既然无缘 2021-02-04 20:09

I am not very familiar with python/ipython but somebody was asking me whether it is possible to start an ipython notebook with a specific python file. It then could be used for

4条回答
  •  Happy的楠姐
    2021-02-04 21:07

    import subprocess, os
    
    def executeJupyter():
        env_dir = "../main_env_dir/"
        os.chdir(env_dir)
    
        # source jupyter_env/bin/activate
        env_activate = "jupyter_env/bin/activate_this.py"
    
        activate_env = exec(open(env_activate).read(), {'__file__': env_activate})
    
        # Open jupyter notebook as a subprocess
        openJupyter = "jupyter notebook"
        subprocess.Popen(openJupyter, shell=True)
    
     executeJupyter()
    

    Make sure you change the env_dir (directory where you have the env of your jupyter notebook) and the env_activate to your own.

提交回复
热议问题