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
文件。在一旦您将
^{pr2}$.ipynb
文件转换为.py
文件。尝试运行
.py
文件以确保它们正常工作。 之后,在终端或命令提示符下使用Pyinstaller。cd
到您的.py
文件位置。 然后打字这将生成一个文件
.exe
程序不,但是可以从
.ipynb
生成.py
脚本,该脚本可以然后转换为.exe带jupyter nbconvert (如果您使用的是Python,这已经包括在内)
在环境中:
将生成
my_notebook.py
。在然后用Pyinstaller:
^{pr2}$现在您的文件夹中应该有一个
my_notebook.exe
和dist文件。在来源:有点过时的Medium Article about this
相关问题 更多 >
编程相关推荐