1. Anaconda/Miniconda

1.1) Create new environment

conda create -n py39 python=3.9

1.2) Add kernel to Jupyter

source activate py39
python -m ipykernel install --name py39
source deactivate

1.3) Install mamba

conda install mamba -n base -c conda-forge

1.4) Add existing R installation to Jupyter

  • Check R home directory:

      R.home("bin")
    
  • In Command Prompt (Windows):

      cd 'C:\Program Files\R\R-4.0.0\bin\x64\'
      conda activate my_env
      R.exe
      install.packages("IRkernel")
      IRkernel::installspec()
      q()
    

2. Matplotlib

  • Import:

      import matplotlib.pyplot as plt
      %matplotlib inline
      plt.rcParams.update({'text.usetex': True, 'figure.dpi':150, 'savefig.dpi':300})
    
  • Use subset of colormap:

      cmap = matplotlib.colors.ListedColormap(plt.cm.tab10.colors[:2])
    

3. Pytables

  • Close all opened files:

      tables.file._open_files.close_all()
    

4. Jupyter

  • Use full width:

      from IPython.display import display, HTML
      display(HTML("<style>.container { width:100% !important; }</style>"))
    

5. Reload (ref)

%load_ext autoreload
%autoreload 2

6. Warnings (ref)

  • Temporary:
      import warnings
    
      def fxn():
          warnings.warn("deprecated", DeprecationWarning)
    
      with warnings.catch_warnings():
          warnings.simplefilter("ignore")
          warnings.filterwarnings("ignore", category=DeprecationWarning)
          fxn()
    

6. HTTP Server (Python 3)

python -m http.server
python -m http.server 8000 --bind 127.0.0.1 --directory /tmp/

Tags:

Categories:

Updated: