python util模块_ImportError:没有名为'util'的模块

I know that there are many variations of this question, but I could not find one like mine. When I try to import the module illustris_python I get the error ImportError: No module named 'util' The module util is in the directory below the module snapshot.py that needs it so I am confused as to why python sees one module , but not the other.

I have included the import call as well as traceback below.

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)]

Type "copyright", "credits" or "license" for more information.

IPython 3.0.0 -- An enhanced Interactive Python.

? -> Introduction and overview of IPython's features.

%quickref -> Quick reference.

help -> Python's own help system.

object? -> Details about 'object', use 'object??' for extra details.

%guiref -> A brief reference about the graphical user interface.

In [1]: import illustris_python as il

Traceback (most recent call last):

File "", line 1, in

import illustris_python as il

File "C:\WinPython-64bit-3.4.3.2\python-3.4.3.amd64\lib\site- packages\illustris_python\__init__.py", line 3, in

from . import *

File "C:\WinPython-64bit-3.4.3.2\python-3.4.3.amd64\lib\site- packages\illustris_python\snapshot.py", line 6, in

from util import partTypeNum

ImportError: No module named 'util'

In [2]:

解决方案

Looking at the BitBucket repo, I'm pretty sure the problem is that this code is Python 2.x-only. Someone's done some work to clean it up for an eventual port, but there's still more to be done.

from util import partTypeNum

In Python 2.6, this is a relative import (it's "deprecated" by PEP 328, but I'm pretty sure you don't actually get the warning by default…), so it first looks in the same package as snapshot.py, where it finds a util.py, before looking through your sys.path.

In Python 3.4, it's an absolute import, so it just looks in your sys.path (well, it calls your top-level module finders, but usually that means looking in your sys.path), and there is no util.py there.

If you're trying to finish porting this sample code to 3.x yourself, just change it to an explicit relative import:

from .util import partTypeNum

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C:\Users\zhang'xin'ge>python -c "import tensorflow as tf; print(tf._version_)" Traceback (most recent call last): File "<string>", line 1, in <module> File "D:\Anaconda\lib\site-packages\tensorflow\__init__.py", line 38, in <module> from tensorflow.python.tools import module_util as _module_util File "D:\Anaconda\lib\site-packages\tensorflow\python\__init__.py", line 37, in <module> from tensorflow.python.eager import context File "D:\Anaconda\lib\site-packages\tensorflow\python\eager\context.py", line 32, in <module> from tensorflow.python import pywrap_tfe File "D:\Anaconda\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 25, in <module> from tensorflow.python._pywrap_tfe import * ImportError: DLL load failed while importing _pywrap_tfe: 找不到指定的模块。 C:\Users\zhang'xin'ge>python -c "import keras; print(keras._version_)" Traceback (most recent call last): File "<string>", line 1, in <module> File "D:\Anaconda\lib\site-packages\keras\__init__.py", line 21, in <module> from tensorflow.python import tf2 File "D:\Anaconda\lib\site-packages\tensorflow\__init__.py", line 38, in <module> from tensorflow.python.tools import module_util as _module_util File "D:\Anaconda\lib\site-packages\tensorflow\python\__init__.py", line 37, in <module> from tensorflow.python.eager import context File "D:\Anaconda\lib\site-packages\tensorflow\python\eager\context.py", line 32, in <module> from tensorflow.python import pywrap_tfe File "D:\Anaconda\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 25, in <module> from tensorflow.python._pywrap_tfe import * ImportError: DLL load failed while importing _pywrap_tfe: 找不到指定的模块
07-23

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值