2023年4月1日土曜日

VS basicからssh接続したLinuxのJupyterで、pandasがimportできなかった

つい最近visual studio codeを導入した。

https://code.visualstudio.com/docs


かなりの便利さに驚愕しているが、特にssh接続した先に置いてあったjupyter のノートブックを扱えることが気に入っている。kernelには接続先のconda で導入したpython3を選択することができる。


VS code上でノートブックを開いてpandas, numpy をインポートする際のエラー

扱っている時、pandasやnumpyのインポート時にエラーを吐いてしまって正常にインポートできない。

 

numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject


Visual studio code経由ではなくjupyter labからはimportされていたのでよく分からない。Incompatibilityが原因ということで、完全には原因はわからなかったが 、updateをかけてみた。



 (base)$ conda update conda 



今度はうまくimportできるようになった。


参考:

以下のサイトでは、versionを落とすことでincompatibilityを回避していた。

https://anton0825.hatenablog.com/entry/2021/09/28/000000

 

2023年3月6日月曜日

Installing Sphinx on mac

Last week I installed Sphinx on my macOS computer to start practicing the document-making by Sphinx. I frequently see the documents of tools and others generated by Sphinx. I like the simple outlook and their well-structured formats  of the sphinx documents. It looks little a bit difficult to start using this tools for me, and I hesitated to introduce this application on my computer. Recently I found O'Reilly's book that seems good for learning Sphinx from scratch. I purchased the book and get started this tool for the first time.


Installation


In the text, there are good concise tutorials to install Sphinx on one's machine (Windows/macOS/Linux). In my case, just install sphinx using conda package manager. 


(base) tk$ conda install -c conda-forge sphinx

Collecting package metadata (current_repodata.json): done

Solving environment: done


## Package Plan ##


  environment location: /Path/to/miniconda3


  added / updated specs:

    - sphinx



The following packages will be downloaded:


    package                    |            build

    ---------------------------|-----------------

    alabaster-0.7.13           |     pyhd8ed1ab_0          18 KB  conda-forge

    docutils-0.19              |  py310h2ec42d9_1         761 KB  conda-forge

    imagesize-1.4.1            |     pyhd8ed1ab_0          10 KB  conda-forge

    snowballstemmer-2.2.0      |     pyhd8ed1ab_0          57 KB  conda-forge

    sphinx-6.1.3               |     pyhd8ed1ab_0         1.2 MB  conda-forge

    sphinxcontrib-applehelp-1.0.4|     pyhd8ed1ab_0          29 KB  conda-forge

    sphinxcontrib-devhelp-1.0.2|             py_0          22 KB  conda-forge

    sphinxcontrib-htmlhelp-2.0.1|     pyhd8ed1ab_0          32 KB  conda-forge

    sphinxcontrib-jsmath-1.0.1 |             py_0           7 KB  conda-forge

    sphinxcontrib-qthelp-1.0.3 |             py_0          25 KB  conda-forge

    sphinxcontrib-serializinghtml-1.1.5|     pyhd8ed1ab_2          27 KB  conda-forge

    ------------------------------------------------------------

                                           Total:         2.1 MB


The following NEW packages will be INSTALLED:


  alabaster          conda-forge/noarch::alabaster-0.7.13-pyhd8ed1ab_0 

  docutils           conda-forge/osx-64::docutils-0.19-py310h2ec42d9_1 

  imagesize          conda-forge/noarch::imagesize-1.4.1-pyhd8ed1ab_0 

  snowballstemmer    conda-forge/noarch::snowballstemmer-2.2.0-pyhd8ed1ab_0 

  sphinx             conda-forge/noarch::sphinx-6.1.3-pyhd8ed1ab_0 

  sphinxcontrib-app~ conda-forge/noarch::sphinxcontrib-applehelp-1.0.4-pyhd8ed1ab_0 

  sphinxcontrib-dev~ conda-forge/noarch::sphinxcontrib-devhelp-1.0.2-py_0 

  sphinxcontrib-htm~ conda-forge/noarch::sphinxcontrib-htmlhelp-2.0.1-pyhd8ed1ab_0 

  sphinxcontrib-jsm~ conda-forge/noarch::sphinxcontrib-jsmath-1.0.1-py_0 

  sphinxcontrib-qth~ conda-forge/noarch::sphinxcontrib-qthelp-1.0.3-py_0 

  sphinxcontrib-ser~ conda-forge/noarch::sphinxcontrib-serializinghtml-1.1.5-pyhd8ed1ab_2 



Proceed ([y]/n)? y




After installation, I checked by,


(base) tk$ sphinx-quickstart --version

sphinx-quickstart 6.1.3



I successfully installed sphinx on my system.


References


Sphinxをはじめよう 第3版 O'REILLY Japan: https://www.oreilly.co.jp/books/9784873119830/
Support page:  https://github.com/getstart-sphinx/getstart-sphinx

2023年3月3日金曜日

Useful jupyter lab extension: jupyterlab_templates

 I daily use the jupyter lab for data analysis workflow. Recently I updated the jupyter lab and I found that the jupyterlab extension manager can be available. Since then I frequently check the jupyterlab extension to make my jupyter environment more useful and productive. 

Jupyterlab Extension Manager -- T.Y. Blog

 There are some stuffs I always use in the notebook such as description markdown cells and import-modules cells for notebooks. Today I found an extension for jupyterlab that seems useful for setting up templates.

Jupyterlab_template

Support for jupyter notebook templates in jupyterlab

The readme can be available from the github page.



Installation

Installation guide is available in github README.md. Since I use conda for package management, I install jupyterlab_templates using  conda install , 



(base) tk$ conda install -c conda-forge jupyterlab_templates

Retrieving notices: ...working... done

Collecting package metadata (current_repodata.json): done

Solving environment: done


## Package Plan ##


  environment location: /Path/to/miniconda3


  added / updated specs:

    - jupyterlab_templates



The following packages will be downloaded:


    package                    |            build

    ---------------------------|-----------------

    jupyterlab_templates-0.3.2 |     pyh1d7be83_0          72 KB  conda-forge

    ------------------------------------------------------------

                                           Total:          72 KB


The following NEW packages will be INSTALLED:


  jupyterlab_templa~ conda-forge/noarch::jupyterlab_templates-0.3.2-pyh1d7be83_0 



Proceed ([y]/n)? y



Then I install jupyterlab_templates on Extension Manager,




Configuration file

Next, adding parameters on  jupyter_notebook_config.py  is necessary to let jupyterlab find the template files in  template_dirs . The jupyter_notebook_config.py is a configration file of jupyterlab. If there is no file on your system yet, it can be generated by


(base) tk$ jupyter lab --generate-config

Writing default config to: /Path/to/home/.jupyter/jupyter_lab_config.py



I edited this file on the terminal to add three lines below,


c.JupyterLabTemplates.template_dirs = ['/Path/to/template/directory']

c.JupyterLabTemplates.include_default = True

c.JupyterLabTemplates.include_core_paths = True

^G Get Help       ^O WriteOut       ^R Read File      ^Y Prev Pg        ^K Cut Text       ^C Cur Pos        

^X Exit           ^J Justify        ^W Where is       ^V Next Pg        ^U UnCut Text     ^T To Spell       


Now the setup of this extension was completed.



Using template from Launcher

I restart the jupyter lab and found the template button was added on Launcher.




Then The preparation of jupyterlab_extension was completed. When clicking the "Template" on Notebook, I can choose the ipynb template on template directory.



Note that the updates of template directories and notebooks are not reflected until the system is once restarted. 



References