是否可以生成Jupyter笔记本的可执行文件(.exe)? [英] Is it possible to generate an executable (.exe) of a jupyter-notebook?

查看:107
本文介绍了是否可以生成Jupyter笔记本的可执行文件(.exe)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jupyter笔记本用python写了一个代码,我想生成该程序的可执行文件.

I wrote a code in python using jupyter notebook and i want to generate an executable of the program.

推荐答案

您可以使用我编写的这段代码将大量的.ipynb文件转换为.py文件.

You can use this code I've written to convert large numbers of .ipynb files into .py files.

srcFolder = r'input_folderpath_here'
desFolder = r'output_folderpath_here'

import os
import nbformat
from nbconvert import PythonExporter

def convertNotebook(notebookPath, modulePath):
    with open(notebookPath) as fh:
        nb = nbformat.reads(fh.read(), nbformat.NO_CONVERT)
    exporter = PythonExporter()
    source, meta = exporter.from_notebook_node(nb)
    with open(modulePath, 'w+') as fh:
        fh.writelines(source)

# For folder creation if doesn't exist
if not os.path.exists(desFolder):
    os.makedirs(desFolder)

for file in os.listdir(srcFolder):
    if os.path.isdir(srcFolder + '\\' + file):
        continue
    if ".ipynb" in file:
        convertNotebook(srcFolder + '\\' + file, desFolder + '\\' + file[:-5] + "py")

.ipynb文件转换为.py文件后.
尝试运行.py文件以确保它们可以工作. 之后,在终端或命令提示符中使用Pyinstaller. cd到您的.py文件位置. 然后输入

Once you have converted your .ipynb files into .py files.
Try running the .py files to ensure they work. After which, use Pyinstaller in your terminal or command prompt. cd to your .py file location. And then type

pyinstaller --onefile yourfile.py

这将生成单个文件.exe程序

这篇关于是否可以生成Jupyter笔记本的可执行文件(.exe)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆