title: Why is the re module trying to import enum.IntFlag?
body: <p>How is it possible that a core module is importing a non-existent name from another core module?</p>
  
  <p>Specifically, the <code>re</code> module importing <code>enum.IntFlag</code></p>
  
  <hr>
  
  <p><strong><em>Ways to Reproduce</em></strong></p>
  
  <p>It can be reproduced by launching an interpreter and attempting the import, running a program that depends on <code>enum.IntFlag</code> such as <code>pip</code>, viewing the interpreter settings page in Eclipse, using the text editor, running the interactive console in PyDev, ...</p>
  
  <p>Directly importing</p>
  
  <pre><code>from enum import IntFlag
  
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  ImportError: cannot import name 'IntFlag'
  </code></pre>
  
  <p>Run a dependant program (pip)</p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/bin/pip", line 4, in &lt;module&gt;
      import re
    File "/usr/lib/python3.6/re.py", line 142, in &lt;module&gt;
      class RegexFlag(enum.IntFlag):
  AttributeError: module 'enum' has no attribute 'IntFlag'
  </code></pre>
  
  <p>Viewing the Python Interpreter settings in Eclipse also produces the above traceback (in the window the interpreter settings would be in).</p>
  
  <p><code>Preferences =:&gt; PyDev =:&gt; Interpreters =:&gt; Python Interpreter</code></p>
  
  <p>Also the text editor doesn't recognise a print statement.</p>
  
  <p>Also, when I run the console interpreter (eg: <code>Ctrl+Alt+Enter</code>, eclipse fails with a popup showing this:</p>
  
  <blockquote>
    <p>'Create Interactive Console' has encountered a problem.</p>
    
    <p>Error initializing console.</p>
    
    <p><em>Error Details</em></p>
  </blockquote>
  
  <p>Click the <em>Error Details</em> button:</p>
  
  <pre><code>Error initializing console.
  Unexpected error connecting to console.
  Failed to recive suitable Hello response from pydevconsole. Last msg received: Console already exited with value: 1 while waiting for an answer.
  
  Command Line used:  /usr/bin/python3.6 -u /usr/lib/eclipse/../../../home/scott/.eclipse/org.eclipse.platform_4.7.1_155965261_linux_gtk_x86_64/plugins/org.python.pydev_6.2.0.201711281614/pysrc/pydevconsole.py 44633 43575 44633 43575
  
  Environment:
  PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/cuda/bin:/usr/lib/jvm/default/bin:/opt/jython/bin/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
  XAUTHORITY=/tmp/xauth-1000-_0
  XDG_DATA_DIRS=/usr/share:/usr/share:/usr/local/share
  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
  XDG_CURRENT_DESKTOP=KDE
  QT_AUTO_SCREEN_SCALE_FACTOR=0
  MAIL=/var/spool/mail/scott
  MOZ_PLUGIN_PATH=/usr/lib/mozilla/plugins
  QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
  SESSION_MANAGER=local/scott-pc:@/tmp/.ICE-unix/976,unix/scott-pc:/tmp/.ICE-unix/976
  LOGNAME=scott
  PAM_KWALLET5_LOGIN=/run/user/1000/kwallet5.socket
  PWD=/home/scott
  XCURSOR_THEME=Azenis
  PYPATH=/code/scott/Py/Path
  PYTHONPATH=/home/scott/.eclipse/org.eclipse.platform_4.7.1_155965261_linux_gtk_x86_64/plugins/org.python.pydev_6.2.0.201711281614/pysrc/pydev_sitecustomize:/mnt/ssdata/scott/code/Py/Path:/home/scott:/usr/lib/python3.6/Tools/scripts:/usr/lib/python3.6/lib-dynload:/usr/lib/python3.6/site-packages:/usr/lib/python3.6
  KDE_SESSION_VERSION=5
  SHELL=/bin/bash
  KDE_MULTIHEAD=false
  KDE_FULL_SESSION=true
  GTK_MODULES=canberra-gtk-module
  GDK_SCALE=1
  DATA=/data/scott/
  XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1
  PYDYNLOAD=/usr/lib/python3.6/lib-dynload
  VM=/vm/scott/
  XDG_SESSION_DESKTOP=KDE
  SHLVL=1
  PYSITE=/usr/lib/python3.6/site-packages
  OXYGEN_DISABLE_INNER_SHADOWS_HACK=1
  PYVER=3.6
  KDE_SESSION_UID=1000
  XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt
  LANG=en_GB.UTF-8
  XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
  XDG_SESSION_ID=c2
  XDG_SESSION_TYPE=x11
  DISPLAY=:0
  PYTHONSTARTUP=/usr/lib/python3.6/startup_hook.py
  GTK_RC_FILES=/etc/gtk/gtkrc:/home/scott/.gtkrc:/home/scott/.config/gtkrc
  ECLIPSE_HOME=/usr/lib/eclipse
  XDG_SESSION_CLASS=user
  XCURSOR_SIZE=56
  LIBOVERLAY_SCROLLBAR=0
  DESKTOP_SESSION=/usr/share/xsessions/plasma
  GDK_CORE_DEVICE_EVENTS=1
  USER=scott
  GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/scott/.gtkrc-2.0:/home/scott/.config/gtkrc-2.0
  XDG_SEAT=seat0
  CODE=/code/scott/
  GS_LIB=/home/scott/.fonts
  PYSCRIPTS=/usr/lib/python3.6/Tools/scripts
  NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat
  XDG_VTNR=1
  XDG_RUNTIME_DIR=/run/user/1000
  HOME=/home/scott
  PYTHONIOENCODING=UTF-8
  PYDEV_UMD_ENABLED=true
  PYDEV_UMD_NAMELIST=guidata,guiqwt
  PYDEV_UMD_VERBOSE=true
  </code></pre>
  
  <hr>
  
  <p><strong><em>Progress</em></strong></p>
  
  <p>in the standard library version <code>/usr/lib/python3.6/enum.py</code>,
  the name <code>enum.IntFlag</code> exists in <code>enum.__all__</code></p>
  
  <p>Is <code>enum</code> being imported from the standard library version? </p>
  
  <pre><code>import enum
  print(enum.__file__)
  # /usr/lib/python3.6/site-packages/enum/__init__.py
  </code></pre>
  
  <p>It is importing from <code>/usr/lib/python3.6/site-packages/enum/__init__.py</code> I checked that file and there is no <code>IntFlag</code>. Also, it's a package init rather than a single file. </p>
  
  <p>There is no <code>/usr/lib/python3.6/site-packages/enum/enum.py</code>. There is a <code>README</code> file that says that this is ver 3.4.</p>
  
  <p>I could replace the contents of <code>__init__.py</code> with <code>enum.py</code></p>
  
  <p>I could delete the <code>site-packages/enum</code> directory</p>
  
  <hr>
  
  <p><strong><em>Solution</em></strong></p>
  
  <p>There is another <code>enum</code> module, a python3.4 compatibility package, that was masking the module version in the standard library.</p>
  
  <p>python34 compatibility package: <code>/usr/lib/python3.6/enum/__init__.py</code> </p>
  
  <p>the standard library module: <code>/usr/lib/python3.6/enum.py</code>.</p>
  
  <p>I deleted the directories:</p>
  
  <pre><code>mkdir enumbackup
  cd enumbackup
  sudo mv /usr/lib/python3.6/enum .
  sudo mv /usr/lib/python3.6/enumenum34-1.1.6.dist-info .
  </code></pre>
  
  <p>Now, <code>enum.__file__</code> shows <code>/usr/lib/python3.6/enum.py</code> as it should and everything works. </p>
  
  <pre><code>from enum import IntFlag
  ## works
  </code></pre>
  
  <p>Thanks for the help! :)</p>