官术网_书友最值得收藏!

Converting a Jupyter Notebook to a Python Script

You can convert a Jupyter Notebook to a Python script. This is equivalent to copying and pasting the contents of each code cell into a single .py file. The Markdown sections are also included as comments.

The conversion can be done from the NotebookApp or in the command line as follows:

jupyter nbconvert --to=python chapter-1-notebook.ipynb

This is useful, for example, when you want to determine the library requirements for a Notebook using a tool such as pipreqs. This tool determines the libraries used in a project and exports them into a requirements.txt file (and it can be installed by running pip install pipreqs).

The command is called from outside the folder containing your .py files. For example, if the .py files are inside a folder called chapter-1, you could do the following:

pipreqs chapter-1/

The resulting requirements.txt file for chapter-1-workbook.ipynb looks like this:

     cat chapter-1/requirements.txt
matplotlib==2.0.2
numpy==1.13.1
pandas==0.20.3
requests==2.18.4
seaborn==0.8
beautifulsoup4==4.6.0
scikit_learn==0.19.0
主站蜘蛛池模板: 阿拉尔市| 竹北市| 申扎县| 江口县| 哈尔滨市| 嘉峪关市| 建湖县| 灵寿县| 京山县| 尼勒克县| 长垣县| 洛川县| 黑山县| 界首市| 习水县| 安平县| 哈尔滨市| 濮阳市| 洪湖市| 蓝山县| 恩施市| 陆丰市| 阆中市| 揭东县| 昌邑市| 江阴市| 永康市| 石狮市| 合江县| 老河口市| 汝州市| 闸北区| 岱山县| 四平市| 和田市| 红河县| 佛冈县| 新巴尔虎右旗| 滨州市| 锡林郭勒盟| 祥云县|