Python Troubleshooting Q&A

This article was first published on SH Fintech Modeling , and kindly contributed to python-bloggers. (You can report issue about the content on this page here)
Want to share your content on python-bloggers? click here.

This is just a small collection of common error messages and solutions that we encounter when using Python.

Python Troubleshooting Q&A

1. Pyfolio – AttributeError: ‘numpy.int64’ object has no attribute ‘to_pydatetime’

  • # remove your installed pyfolio library
    pip uninstall pyfolio
    # Install it again from its github repo
    pip install git+https://github.com/quantopian/pyfolio

2. For using git, add git path to the PATH on Windows

  • Find Git executable file (git.exe) is located
    in C:\Program Files\Git\bin
    or C:\Program Files\Git\cmd
    or C:\Users\XXX\AppData\Local\GitHubDesktop\app-3.0.6\resources\app\git\cmd
    or other directories

    The directory that is found must be added to the PATH environment variable and the version of Git needs to be confirmed as follows.

    C:\Users\shlee>git –version
    git version 2.35.4.windows.1

3. TabError: inconsistent use of tabs and spaces in indentation

  • This problem occurs when we mix tabs and spaces in the same code block. To solve the error, remove the spacing and only use tabs or spaces, but don’t mix the two in the same code block.

4. Multiple prints in Jupyter notebook

# InteractiveShell.ast_node_interactivity 
# : ‘all’ | ‘last’ | ‘last_expr’ | ‘none’ 
# (default : ‘last_expr’)
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = “all”

5. ValueError: Please initialize `Bidirectional` layer with a `tf.keras.layers.Layer` instance.

Just delete tensorflow.

#from tensorflow.keras.layers import Bidirectional, Dropout, Activation, Dense, LSTM
#from tensorflow.python.keras.layers import CuDNNLSTM
#from tensorflow.keras.models import Sequential

from keras.layers import Bidirectional, Dropout, Activation, Dense, LSTM
from keras.layers import CuDNNLSTM
from keras.models import Sequential

to be added….

To leave a comment for the author, please follow the link and comment on their blog: SH Fintech Modeling .

Want to share your content on python-bloggers? click here.