Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: required field "type_ignores" missing from Module

Note: I have read Python: TypeError: required field "type_ignores" missing from Module in Jupyter notebook, which contains a similar problem. However, I am still stuck.

Problem: I have just updated from Python 3.7.5 to Python 3.8.5. However, when I run code in Jupyter Notebook, the following error message is displayed:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codeop.py in __call__(self, source, filename, symbol)
    139 
    140     def __call__(self, source, filename, symbol):
--> 141         codeob = compile(source, filename, symbol, self.flags, 1)
    142         for feature in _features:
    143             if codeob.co_flags & feature.compiler_flag:

TypeError: required field "type_ignores" missing from Module

I get this message when I run code like

i = 1

or code like

import numpy as np

or code like

from platform import python_version

print(python_version()) 

I have read Python: TypeError: required field "type_ignores" missing from Module in Jupyter notebook, which contains a similar problem. However, the poster in that question had an outdated ipython version. I did a

pip freeze

and found that I had the newest version (7.2.0), which means that the solution to that problem does not apply to this problem.

Below is some extra information if you need:

What I tried: I first tried to revert from Python 3.8 to Python 3.7. This is because the error message mentioned that the error was coming from /usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codeop.py I tried to do this by downloading pyenv and python 3.7 again (I had python 3.7 before but it had disappeared) and setting the python version to 3.7.5 by configuring the .zshenv file. However, that caused jupyter notebook and even programs like emacs to stop working with messages like

command not found: jupyter

and

command not found: emacs

I finally did it by downloading the python 3.7.5 pkg file from the python website:

python --version

output:

Python 3.7.5

However, when I launch Jupyter Notebook, I still get the same error as before ("TypeError: required field "type_ignores" missing from Module"). I am afraid that installing Python 3.8 did some permanent damage.

This is my .zshenv file configuration:

export SACAUX=SACHOME/aux
export SACHOME=/usr/local/sac
export PATH=${PATH}:${SACHOME}/bin
export PATH=SACHOME/bin
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:SACHOME/bin
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:SACHOME/bin:HOME/.pyenv/bin
export PATH=~/.pyenv/versions/3.7.5/bin:${PATH}
export PYTHONPATH=/usr/local/lib/python3.7/site-packages

FYI, (If this is useful), All of the packages I need (tensorflow, numpy, scipy) are in /usr/local/lib/python3.7/site-packages, a python 3.7 folder, so I had to explicitly set PYTHONPATH to /usr/local/lib/python3.7/site-packages so that Python can find the packages to import.

What are some fixes to solve this "TypeError: required field "type_ignores" missing from Module"?

like image 408
ntlarry Avatar asked Aug 27 '20 04:08

ntlarry


2 Answers

I don't mean to revive a dead question, but I saw that someone commented asking for an answer to this recently and this is the top result when searching for this problem.

I had this issue and apparently it was an issue with the Werkzeug package implementation in an older version, I fixed it by updating it from version 0.15.4 to 1.0.1 using pip:

pip install werkzeug --upgrade

this should fix your issue; if you'd like to know which version you're on, launch a terminal and launching the Python interactive terminal using the command python:

import werkzeug
werkzeug.__version__
like image 118
Nour Talaat Avatar answered Nov 14 '22 23:11

Nour Talaat


Tried fixing it with werkzeug update and it did not work. On ubuntu 20.04.2

Found this issue for a package I am not sure I am using but mentions updating iPython.

pip3 install ipython --upgrade

it then updated some python packages but not others. And now it seems to work.

like image 26
Andres Avatar answered Nov 15 '22 00:11

Andres