<p dir="auto">Hi I encounter following issue, when I run "import tensorflow as tf" with python</p>
<p dir="auto">install command I used:<br>
<code class="notranslate">pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl</code></p>
<p dir="auto">python version<br>
<code class="notranslate">Python 3.7.0</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py&quot;, line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\imp.py&quot;, line 297, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py&quot;, line 58, in &lt;module&gt;
    from tensorflow.python.pywrap_tensorflow_internal import *
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py&quot;, line 28, in &lt;module&gt;
    _pywrap_tensorflow_internal = swig_import_helper()
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py&quot;, line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py&quot;, line 24, in &lt;module&gt;
    from tensorflow.python import *
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\__init__.py&quot;, line 49, in &lt;module&gt;
    from tensorflow.python import pywrap_tensorflow
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py&quot;, line 72, in &lt;module&gt;
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py&quot;, line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\imp.py&quot;, line 297, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py&quot;, line 58, in &lt;module&gt;
    from tensorflow.python.pywrap_tensorflow_internal import *
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py&quot;, line 28, in &lt;module&gt;
    _pywrap_tensorflow_internal = swig_import_helper()
  File &quot;C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py&quot;, line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help."><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\imp.py", line 297, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in &lt;module&gt;
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in &lt;module&gt;
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 24, in &lt;module&gt;
    from tensorflow.python import *
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\__init__.py", line 49, in &lt;module&gt;
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 72, in &lt;module&gt;
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\imp.py", line 297, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in &lt;module&gt;
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in &lt;module&gt;
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\victor\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
</code></pre></div>
<ul dir="auto">
<li></li>
</ul>
<p dir="auto">What's the problem here? Thank you for your help!</p>
<p dir="auto">Examples on the web demonstrate signaling the end of queue data by calling queue.close() in the data producer and then catching the tf.errors.OutOfRangeError exception in the data consumer.</p>
<p dir="auto">This works fine for a single epoch, but I do multiple epochs, alternating between training data and testing data, and I can't reuse the queue after calling queue.close().</p>
<p dir="auto">The two solutions that I have thought of using the existing code are:</p>
<ol dir="auto">
<li>enqueue() some sentinel at the end of an epoch in the data producer and then tf.Assert() against the sentinel and catch the tf.errors.InvalidArgumentError in the data consumer.</li>
<li>know the number of enqueue's for the epoch and only dequeue that number.<br>
Both seem a little hacky.</li>
</ol>
<p dir="auto">Multi-epoch use of queues might be simplified by adding one of the following:</p>
<ol dir="auto">
<li>A queue.reset(), that throws one tf.errors.OutOfRangeError on dequeue() or some other exception.</li>
<li>A queue.close(reset=True), that only throws one tf.errors.OutOfRangeError on dequeue() or some other exception.</li>
</ol>
<p dir="auto">example usage of 1):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="q = tf.FIFOQueue(...)
placeholder = ...
enqueue_op = q.enqueue(placeholder)
....

def producer(data_dir, sess, q, enqueue_op, placeholder):
  for ...:
    sess.run(enqueue_op, {placeholder:...})
  sess.run(q.reset())

def do_epoch(data_dir, learn):
  threading.Thread(target=producer, args=(data_dir, sess, q, enqueue_op, placeholder)).start()
  while True:
    try:
      sess.run(...)
    exception tf.errors.OutOfRangeError:
      break

for epoch in range(NUM_EPOCHS):
  ... = do_epoch(TRAIN_DIR, learn=True)
  ... = do_epoch(TEST_DIR, learn=False)"><pre class="notranslate"><code class="notranslate">q = tf.FIFOQueue(...)
placeholder = ...
enqueue_op = q.enqueue(placeholder)
....

def producer(data_dir, sess, q, enqueue_op, placeholder):
  for ...:
    sess.run(enqueue_op, {placeholder:...})
  sess.run(q.reset())

def do_epoch(data_dir, learn):
  threading.Thread(target=producer, args=(data_dir, sess, q, enqueue_op, placeholder)).start()
  while True:
    try:
      sess.run(...)
    exception tf.errors.OutOfRangeError:
      break

for epoch in range(NUM_EPOCHS):
  ... = do_epoch(TRAIN_DIR, learn=True)
  ... = do_epoch(TEST_DIR, learn=False)
</code></pre></div>