pybedtools:ImportError:无法导入名称脚本

时间:2021-06-15 23:08:44

I am trying to import Pybedtools in Spyder.

我想在Spyder中导入Pybedtools。

from pybedtools import BedTool

This is the error I am getting:

这是我得到的错误:

Traceback (most recent call last):

 File "<ipython-input-13-7a8ea5d1dea8>", line 1, in <module>
 from pybedtools import BedTool

 File "/Users/michaelsmith/anaconda2/lib/python2.7/site-packages/pybedtools/__init__.py", line 9, in <module>
 from . import scripts

ImportError: cannot import name scripts

I just downloaded Anaconda and there doesn't seem to be a reason as to why this happens. What is the typical protocol for resolving bugs like this?

我刚刚下载了Anaconda,似乎没有理由说明为什么会这样。解决这类错误的典型协议是什么?

UPDATE:

So within my pybedtools folder there is a scripts folder (which is presumably the module we're trying to import). I changed both the command within __init__.py to:

所以在我的pybedtools文件夹中有一个脚本文件夹(可能是我们试图导入的模块)。我将__init__.py中的两个命令都更改为:

from . import scripts2

and changed the name of the folder to scripts2 as well. However, I still get the error as such:

并将文件夹的名称也更改为scripts2。但是,我仍然得到错误:

ImportError: cannot import name scripts2

So I must be doing something wrong here, which module should I be renaming exactly? Sorry if this is a silly question, I am quite new to python.

所以我必须在这里做错事,我应该重命名哪个模块?对不起,如果这是一个愚蠢的问题,我对python很新。

1 个解决方案

#1


0  

This is caused because Anaconda has a module named scripts and therefore your import is "shadowed" by that module. You can double check that when you call import scripts in a new notebook it works even if you have never defined such a module. A very good explanation of import traps can be found here:

这是因为Anaconda有一个名为scripts的模块,因此您的导入被该模块“遮蔽”。您可以仔细检查当您在新笔记本中调用导入脚本时,即使您从未定义过这样的模块,它也能正常工作。可以在此处找到有关导入陷阱的非常好的解释:

http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html

A workaround would be to rename the script module of pybedtools to something else and also change all the imports to the new name.

解决方法是将pybedtools的脚本模块重命名为其他内容,并将所有导入更改为新名称。

#1


0  

This is caused because Anaconda has a module named scripts and therefore your import is "shadowed" by that module. You can double check that when you call import scripts in a new notebook it works even if you have never defined such a module. A very good explanation of import traps can be found here:

这是因为Anaconda有一个名为scripts的模块,因此您的导入被该模块“遮蔽”。您可以仔细检查当您在新笔记本中调用导入脚本时,即使您从未定义过这样的模块,它也能正常工作。可以在此处找到有关导入陷阱的非常好的解释:

http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html

A workaround would be to rename the script module of pybedtools to something else and also change all the imports to the new name.

解决方法是将pybedtools的脚本模块重命名为其他内容,并将所有导入更改为新名称。