Skip to content

KeyError: 'builtins' #3761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nme01 opened this issue Jul 24, 2017 · 7 comments
Closed

KeyError: 'builtins' #3761

nme01 opened this issue Jul 24, 2017 · 7 comments

Comments

@nme01
Copy link

nme01 commented Jul 24, 2017

When I ran mypy using the following command:

mypy -p quant-fin --follow-imports=silent --show-traceback

I got the following error:

qstrader\version.py:1: error: Cannot find module named 'builtins'
Traceback (most recent call last):
  File "c:\users\jacek\appdata\local\programs\python\python35\lib\runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\jacek\appdata\local\programs\python\python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Scripts\mypy.exe\__main__.py", line 9, in <module>
    sys.exit(console_entry())
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\__main__.py", line 7, in console_entry
    main(None)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\main.py", line 50, in main
    res = type_check_only(sources, bin_dir, options)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\main.py", line 97, in type_check_only
    options=options)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\build.py", line 196, in build
    graph = dispatch(sources, manager)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\build.py", line 1769, in dispatch
    process_graph(graph, manager)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\build.py", line 2012, in process_graph
    process_stale_scc(graph, scc, manager)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\build.py", line 2107, in process_stale_scc
    graph[id].semantic_analysis()
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\build.py", line 1664, in semantic_analysis
    self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options, patches)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\semanal.py", line 295, in visit_file
    self.accept(d)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\semanal.py", line 3636, in accept
    node.accept(self)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\nodes.py", line 565, in accept
    return visitor.visit_func_def(self)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\semanal.py", line 418, in visit_func_def
    self.analyze_function(defn)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\semanal.py", line 598, in analyze_function
    defn.type = self.type_analyzer().visit_callable_type(defn.type, nested=False)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\typeanal.py", line 333, in visit_callable_type
    fallback=t.fallback or self.named_type('builtins.function'),
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\typeanal.py", line 545, in named_type
    node = self.lookup_fqn_func(fully_qualified_name)
  File "C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\site-packages\mypy\semanal.py", line 3482, in lookup_fully_qualified
    n = self.modules[parts[0]]
KeyError: 'builtins'
@gvanrossum
Copy link
Member

This is almost always caused by something in the mypy installation. It's not easy to debug without sitting next to you.

@nme01
Copy link
Author

nme01 commented Jul 24, 2017

I tried installing it using both:
python -m pip install mypy
and
python -m pip install -U git+git://github.com/python/mypy.git.

I am using Windows 10 and Python 3.5.2 (from python.org).
I don't know what other information could be useful for debugging the issue.

@Michael0x2a
Copy link
Collaborator

I you can isolate your codebase down into a minimal example that reproduces the problem and share it, that would be helpful.

You can also try re-running mypy with verbose mode enabled: do mypy -p quant-fin --follow-imports=silent --show-traceback -v -v.

Incidentally, does your project have a module or file named builtins? That might be causing some internal conflicts with mypy in some way.

@nme01
Copy link
Author

nme01 commented Jul 24, 2017

I ran it on a single file, which I've had extracted from the workspace, so that other files don't get imported by accident. It's content:

import datetime


def iso_to_gregorian(iso_year: int, iso_week: int, iso_day: int):
    fourth_jan = datetime.date(iso_year, 1, 4)
    _, fourth_jan_week, fourth_jan_day = fourth_jan.isocalendar()
    return fourth_jan + datetime.timedelta(days=iso_day-fourth_jan_day, weeks=iso_week-fourth_jan_week)

What I've got after running mypy iso_to_gregorian.py --follow-imports=silent --show-traceback -v -v:

LOG:  Mypy version 0.530-dev-b6bcdc0038fa3fbca54190b5b66e5e5d95f67acc
LOG:  Metadata not found for iso_to_gregorian
LOG:  Parsing iso_to_gregorian.py (iso_to_gregorian)
LOG:  Loaded graph with 1 nodes
LOG:  Found 1 SCCs; largest has 1 nodes
TRACE: Priorities for iso_to_gregorian:
LOG:  Processing SCC singleton (iso_to_gregorian) as inherently stale
iso_to_gregorian.py:4: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.530-dev-b6bcdc0038fa3fbca54190b5b66e5e5d95f67acc
iso_to_gregorian.py:4: note: use --pdb to drop into pdb
LOG:  Build finished in 0.016 seconds with 1 modules, 0 types, and 16 errors

And answering your question:

Incidentally, does your project have a module or file named builtins?

No, it doesn't.

@emmatyping
Copy link
Member

@nme01 I have a couple ideas. I've had issues where if I install via pip then install again from git, it can cause conflicts. Can you run python -m pip uninstall mypy and verify that there is not a mypy.exe in C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Scripts? Additionally search for a left over typeshed directory in C:\Users\Jacek\AppData\Local\Programs\Python\Python35\Lib\mypy after uninstalling. If anything is left, delete it. Then try running python-m pip install mypy.

@emmatyping
Copy link
Member

@nme01 Could you try python -m pip install git+https://github.com/python/mypy.git that should either: a) fix your installation or b) help us narrow down issues with your install.

@emmatyping
Copy link
Member

Solved in #3991

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants