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

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
主站蜘蛛池模板: 岳阳市| 富宁县| 西乌| 塘沽区| 泸西县| 衡阳县| 北碚区| 石河子市| 通渭县| 天祝| 临朐县| 裕民县| 丰顺县| 旬阳县| 明光市| 榆中县| 顺昌县| 眉山市| 舟山市| 炎陵县| 新绛县| 桦南县| 都安| 安达市| 华阴市| 平度市| 廉江市| 北流市| 白水县| 嫩江县| 兴山县| 通州市| 夏邑县| 荔浦县| 略阳县| 连州市| 绥江县| 城市| 新和县| 温泉县| 汶上县|