.pyc file gets created when it is not even imported
<p>I have 2 Python files called <code>numbers.py</code> and <code>numpyBasicOps.py</code>.  <code>numbers.py</code> is a simple Python file, not importing any module. <code>numpyBasicOps.py</code> imports the <code>numpy</code> library.</p>

<p>Whenever I run <code>numpyBasicOps.py</code>, <code>numbers.py</code>'s output is displayed first followed by some error relating to <code>numpy</code> module:</p>

<pre><code>Traceback (most recent call last):
  File "./numpyBasicOps.py", line 3, in &lt;module&gt;
    import numpy as np
  File "/Library/Python/2.7/site-packages/numpy-1.11.2rc1-py2.7-macosx-10.11-intel.egg/numpy/__init__.py", line 142, in &lt;module&gt;
    from . import add_newdocs
  File "/Library/Python/2.7/site-packages/numpy-1.11.2rc1-py2.7-macosx-10.11-intel.egg/numpy/add_newdocs.py", line 13, in &lt;module&gt;
    from numpy.lib import add_newdoc
  File "/Library/Python/2.7/site-packages/numpy-1.11.2rc1-py2.7-macosx-10.11-intel.egg/numpy/lib/__init__.py", line 8, in &lt;module&gt;
    from .type_check import *
  File "/Library/Python/2.7/site-packages/numpy-1.11.2rc1-py2.7-macosx-10.11-intel.egg/numpy/lib/type_check.py", line 11, in &lt;module&gt;
    import numpy.core.numeric as _nx
  File "/Library/Python/2.7/site-packages/numpy-1.11.2rc1-py2.7-macosx-10.11-intel.egg/numpy/core/__init__.py", line 22, in &lt;module&gt;
    from . import _internal  # for freeze programs
  File "/Library/Python/2.7/site-packages/numpy-1.11.2rc1-py2.7-macosx-10.11-intel.egg/numpy/core/_internal.py", line 15, in &lt;module&gt;
    from .numerictypes import object_
  File "/Library/Python/2.7/site-packages/numpy-1.11.2rc1-py2.7-macosx-10.11-intel.egg/numpy/core/numerictypes.py", line 962, in &lt;module&gt;
    _register_types()
  File "/Library/Python/2.7/site-packages/numpy-1.11.2rc1-py2.7-macosx-10.11-intel.egg/numpy/core/numerictypes.py", line 958, in _register_types
    numbers.Integral.register(integer)
AttributeError: 'module' object has no attribute 'Integral'
</code></pre>

<p>Also, I see a <code>.pyc</code> file for <code>numbers.py</code> being generated.</p>

<p>How does the <code>numbers.pyc</code> file get generated even when it is not imported in <code>numpyBasicOps.py</code> and why is output for <code>numbers.py</code> displayed?</p>

<p><code>numpy</code> registers their own integer-like objects as implementing the Abstract Base Class <a href="https://docs.python.org/2/library/numbers.html#numbers.Integral" rel="nofollow"><code>numbers.Integral</code></a>. To do this, it must use <code>import numbers</code> to get access to that object.</p>

<p>Or at least, it tried to and failed; as you named your module <code>numbers</code> <em>as well</em> it was imported instead. In other words, your <code>numbers.py</code> module masked the built-in <a href="https://docs.python.org/2/library/numbers.html" rel="nofollow">standard library module <code>numbers</code></a>.</p>

<p>Rename your module to something else, and make sure you delete the <code>numbers.pyc</code> file that was created.</p>

python python-2.7 numpy