python之import异常-ImportError: cannot import name xxx

bug:

最近开发中遇到了import异常
目录A下的py文件B import 目录C下的py文件D抛出import异常

ImportError: cannot import name D

analyze:

一般情况这个exception是python找不到import进来的包或库导致的,
排查了一番后还没找到问题根源,总结了下情况:

  • A,C目录名和B,D文件名都没写错;
  • B,D两个py文件进行单文件执行都会抛此异常;
  • 其他任何的py文件import这B,D文件没抛此异常,可以正常执行;

result:

最终确定异常是因为两个py文件互相import导致的异常。悲催发现是因为在没注意到原先文件代码中已经存在import关系

发布了22 篇原创文章 · 获赞 5 · 访问量 3万+
展开阅读全文

tensorboard提示错误cannot import name 'dump_age'

04-03

最开始使用tensorboard的时候是没有问题的,但是不知道为什么,用了几次之后就变成了这样,每次都是提示cannot import name 'dump age',之前没有遇到过这种错误,希望有大佬可以帮忙解答一下。非常感谢 代码是没有问题的,我用最开始用过的代码提示也是这样,想在相当于整个tensorboard不能用了。 图片我就不上传了,截的图一直没办法上传,有点蛋疼! CMD中执行的命令如下: C:\Users\Lenovo>e: E:\>cd E:\Python\Jupyter notebook\Tensorflow-study\inception_log E:\Python\Jupyter notebook\Tensorflow-study\inception_log>tensorboard --host=127.0.0.1 Traceback (most recent call last): File "e:\anaconda3\envs\tensorflow-gpu\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "e:\anaconda3\envs\tensorflow-gpu\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "E:\Anaconda3\envs\tensorflow-gpu\Scripts\tensorboard.exe\__main__.py", line 5, in <module> File "e:\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorboard\main.py", line 45, in <module> from tensorboard import default File "e:\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorboard\default.py", line 37, in <module> from tensorboard.plugins.audio import audio_plugin File "e:\anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorboard\plugins\audio\audio_plugin.py", line 23, in <module> from werkzeug import wrappers File "e:\anaconda3\envs\tensorflow-gpu\lib\site-packages\werkzeug\__init__.py", line 151, in <module> __import__('werkzeug.exceptions') File "e:\anaconda3\envs\tensorflow-gpu\lib\site-packages\werkzeug\exceptions.py", line 71, in <module> from werkzeug.wrappers import Response File "e:\anaconda3\envs\tensorflow-gpu\lib\site-packages\werkzeug\wrappers\__init__.py", line 26, in <module> from .common_descriptors import CommonRequestDescriptorsMixin File "e:\anaconda3\envs\tensorflow-gpu\lib\site-packages\werkzeug\wrappers\common_descriptors.py", line 6, in <module> from ..http import dump_age ImportError: cannot import name 'dump_age' E:\Python\Jupyter notebook\Tensorflow-study\inception_log> 问答

为什么在使用catalyst 时候一直有提示错误ImportError: cannot import name 'run_algorithm'?

06-04

如题: 以下为我的环境: py 3.6 aiodns==1.1.1 aiohttp==3.5.4 alabaster==0.7.12 alembic==0.9.7 appnope==0.1.0 asn1crypto==0.24.0 astroid==2.2.5 async-timeout==3.0.1 attrdict==2.0.1 attrs==19.1.0 Babel==2.6.0 backcall==0.1.0 bcolz==1.2.1 bleach==3.1.0 boto3==1.5.27 botocore==1.8.50 Bottleneck==1.2.1 cchardet==2.1.1 ccxt==1.17.94 certifi==2019.3.9 cffi==1.12.3 chardet==3.0.4 click==6.7 cloudpickle==1.0.0 contextlib2==0.5.5 cryptography==2.6.1 cycler==0.10.0 cyordereddict==1.0.0 Cython==0.27.3 cytoolz==0.9.0.1 decorator==4.4.0 defusedxml==0.6.0 docutils==0.14 empyrical==0.2.2 enigma-catalyst==0.5.21 entrypoints==0.3 eth-abi==1.3.0 eth-account==0.2.3 eth-hash==0.2.0 eth-keyfile==0.5.1 eth-keys==0.2.2 eth-rlp==0.1.2 eth-typing==2.1.0 eth-utils==1.6.0 hexbytes==0.1.0 idna==2.8 idna-ssl==1.1.0 imagesize==1.1.0 inflection==0.3.1 intervaltree==2.1.0 ipykernel==5.1.0 ipython==7.5.0 ipython-genutils==0.2.0 isort==4.3.19 jedi==0.13.3 Jinja2==2.10.1 jmespath==0.9.4 jsonschema==3.0.1 jupyter-client==5.2.4 jupyter-core==4.4.0 keyring==18.0.0 kiwisolver==1.1.0 lazy-object-proxy==1.4.1 Logbook==0.12.5 lru-dict==1.1.6 lxml==4.3.3 Mako==1.0.7 MarkupSafe==1.1.1 matplotlib==3.1.0 mccabe==0.6.1 mistune==0.8.4 mkl-fft==1.0.12 mkl-random==1.0.2 more-itertools==7.0.0 multidict==4.5.2 multipledispatch==0.4.9 nbconvert==5.5.0 nbformat==4.4.0 networkx==2.1 numexpr==2.6.4 numpy==1.16.0 numpydoc==0.9.1 packaging==19.0 pandas==0.24.2 pandas-datareader==0.6.0 pandocfilters==1.4.2 parsimonious==0.8.1 parso==0.4.0 patsy==0.5.1 pexpect==4.7.0 pickleshare==0.7.5 prompt-toolkit==2.0.9 psutil==5.6.2 ptyprocess==0.6.0 pycares==3.0.0 pycodestyle==2.5.0 pycparser==2.19 pycryptodome==3.8.2 pyflakes==2.1.1 Pygments==2.4.0 pylint==2.3.1 pyOpenSSL==19.0.0 pyparsing==2.4.0 pyrsistent==0.14.11 PySocks==1.7.0 python-dateutil==2.8.0 python-editor==1.0.4 pytz==2019.1 pyzmq==18.0.0 QtAwesome==0.5.7 qtconsole==4.5.1 QtPy==1.7.1 Quandl==3.4.5 redo==2.0.1 requests==2.21.0 requests-file==1.4.3 requests-ftp==0.3.1 requests-toolbelt==0.8.0 rlp==1.1.0 rope==0.14.0 s3transfer==0.1.13 scipy==1.2.1 six==1.12.0 snowballstemmer==1.2.1 sortedcontainers==1.5.9 Sphinx==2.0.1 sphinxcontrib-applehelp==1.0.1 sphinxcontrib-devhelp==1.0.1 sphinxcontrib-htmlhelp==1.0.2 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.2 sphinxcontrib-serializinghtml==1.1.3 spyder==3.3.4 spyder-kernels==0.4.4 SQLAlchemy==1.2.2 statsmodels==0.9.0 tables==3.4.2 testpath==0.4.2 toolz==0.9.0 tornado==6.0.2 traitlets==4.3.2 typed-ast==1.3.4 typing-extensions==3.7.2 urllib3==1.24.3 wcwidth==0.1.7 web3==4.4.1 webencodings==0.5.1 websockets==5.0.1 wrapt==1.11.1 wurlitzer==1.0.2 yarl==1.1.0 在运行catalyst 的时候会提示: runfile('/Users/mac/Desktop/UPF/Master Thesis/py/crypocurrency/trading.py', wdir='/Users/mac/Desktop/UPF/Master Thesis/py/crypocurrency') Traceback (most recent call last): File "<ipython-input-10-5dde7acc5e52>", line 1, in <module> runfile('/Users/mac/Desktop/UPF/Master Thesis/py/crypocurrency/trading.py', wdir='/Users/mac/Desktop/UPF/Master Thesis/py/crypocurrency') File "/Users/mac/miniconda3/envs/catalyst/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile execfile(filename, namespace) File "/Users/mac/miniconda3/envs/catalyst/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "/Users/mac/Desktop/UPF/Master Thesis/py/crypocurrency/trading.py", line 6, in <module> from catalyst import run_algorithm File "/Users/mac/Desktop/UPF/Master Thesis/py/crypocurrency/catalyst.py", line 1, in <module> from catalyst import run_algorithm ImportError: cannot import name 'run_algorithm' 我在网上找了很久的解决方案但是都没有一个能解决到的。 会不会是因为在安装catalyst的时候就已经出了这个问题所导致的? 以下为我在安装的时候发生的错误。 请各位大神帮帮忙! ERROR: Cannot uninstall 'certifi'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. Note: you may need to restart the kernel to use updated packages. 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览