Skip to content

ImportError: cannot import name mkdtemp #4620

Closed

Description

@rabby410002

while using cython to compile "seq_dataset.pyx"
I met this error :

  File "C:\Users\Hsuan\Anaconda\lib\site-packages\numpy\testing\utils.py", line
15, in <module>
    from tempfile import mkdtemp
ImportError: cannot import name mkdtemp

i tried to put tempfile.py just under the same filefolder but still not work
is it because there are some conflicts of redundant name or...?
does anyone know how to solve this problem?

this is the whole bug message:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\Main.py", line
 633, in main
    result = compile(sources, options)
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\Main.py", line
 608, in compile
    return compile_multiple(source, options)
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\Main.py", line
 581, in compile_multiple
    context = options.create_context()
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\Main.py", line
 506, in create_context
    self.cplus, self.language_level, options=self)
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\Main.py", line
 61, in __init__
    import Builtin, CythonScope
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\CythonScope.py
", line 3, in <module>
    from UtilityCode import CythonUtilityCode
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\UtilityCode.py
", line 1, in <module>
    from TreeFragment import parse_from_strings, StringParseContext
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\TreeFragment.p
y", line 10, in <module>
    from Visitor import VisitorTransform
  File "Visitor.py", line 11, in init Cython.Compiler.Visitor (Cython\Compiler\V
isitor.c:16378)
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\ExprNodes.py",
 line 3755, in <module>
    class SliceIndexNode(ExprNode):
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Compiler\ExprNodes.py",
 line 3892, in SliceIndexNode
    "SliceObject", "ObjectHandling.c", context={'access': 'Get'})
  File "Code.py", line 275, in Cython.Compiler.Code.UtilityCodeBase.load (Cython
\Compiler\Code.c:7470)

  File "Code.py", line 462, in Cython.Compiler.Code.TempitaUtilityCode.__init__
(Cython\Compiler\Code.c:11410)

  File "Code.py", line 455, in Cython.Compiler.Code.sub_tempita (Cython\Compiler
\Code.c:11151)

  File "C:\Users\Hsuan\Anaconda\lib\site-packages\Cython\Tempita\__init__.py", l
ine 4, in <module>
    from _tempita import *
  File "_tempita.py", line 34, in init Cython.Tempita._tempita (Cython\Tempita\_
tempita.c:27816)
  File "C:\Users\Hsuan\Anaconda\lib\cgi.py", line 50, in <module>
    import mimetools
  File "C:\Users\Hsuan\Anaconda\lib\mimetools.py", line 6, in <module>
    import tempfile
  File "tempfile.py", line 35, in <module>
    from random import Random as _Random
  File "random.py", line 5, in <module>
    import numpy as np
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\numpy\__init__.py", line 185,
in <module>
    from . import add_newdocs
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\numpy\add_newdocs.py", line 13
, in <module>
    from numpy.lib import add_newdoc
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\numpy\lib\__init__.py", line 8
, in <module>
    from .type_check import *
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\numpy\lib\type_check.py", line
 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\numpy\core\__init__.py", line
46, in <module>
    from numpy.testing import Tester
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\numpy\testing\__init__.py", li
ne 13, in <module>
    from .utils import *
  File "C:\Users\Hsuan\Anaconda\lib\site-packages\numpy\testing\utils.py", line
15, in <module>
    from tempfile import mkdtemp
ImportError: cannot import name mkdtemp

Activity

  1. amueller commented on Apr 19, 2015

    @amueller
    Member

    there should not be a file called tempfile there. this is a built-in python module. can you run the import in python?

  2. kjasinska commented on May 14, 2015

    @kjasinska

    I have the same problem during cythonization of seq_dataset.pyx. I can import the tempfile module in python.

  3. amueller commented on May 14, 2015

    @amueller
    Member

    Do you get the same traceback? I am not sure if it is numpy that can't import mkdtemp or temp that can't import numpy.
    Either way, maybe there is some mismatch between your cython and your python?
    Can you compile a cython file that just imports numpy?

  4. rabby410002 commented on May 15, 2015

    @rabby410002
    Author

    @oiah I re-install the whole python package and it works now, maybe there are some mismatch or mistakes when you modify the code.Just try to re-install packages and compile seq_dataset.pyx before any modification of it.

  5. amueller commented on Jun 15, 2015

    @amueller
    Member

    closing as I feel this is unrelated.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions