简体   繁体   English

Google Colab:ModuleNotFoundError:没有名为“base_positioner”的模块

[英]Google Colab : ModuleNotFoundError: No module named 'base_positioner'

I am working on a python program in colab.我正在 colab 中研究 python 程序。 I need to import another file here.我需要在这里导入另一个文件。 The file is saved by the name "base_positioner.ipynb" in google drive.... I have gone through multiple resources to see how to do this import and I have done the following:该文件以名称“base_positioner.ipynb”保存在谷歌驱动器中......我已经浏览了多个资源以查看如何进行此导入,并且我已经完成了以下操作:

from google.colab import drive
drive.mount('/content/gdrive')
%cd /content/gdrive/My Drive

On running !ls , I see 'base_positioner.ipynb' in the list but still running: import base_positioner throws the module not found error在运行!ls时,我在列表中看到 'base_positioner.ipynb' 但仍在运行: import base_positioner throws the module not found 错误

I had also tried the following but with no success in importing the desired file:我也尝试了以下方法,但没有成功导入所需的文件:

sys.path.append('/content/gdrive/My Drive/Colab Notebooks')

What else should I try??我还应该尝试什么?

This could happen if you haven't mounted your Drive on Colab to the backend properly and also possibly if your file layout in Drive is distinct from the file layout in Colab.如果您未将 Colab 上的 Drive 正确安装到后端,并且 Drive 中的文件布局与 Colab 中的文件布局不同,则可能会发生这种情况。 Are you running the import command without running the following code?您是否在不运行以下代码的情况下运行导入命令?

from google.colab import drive
drive.mount('/content/gdrive')
%cd /content/gdrive/My Drive

If you are doing that then this won't work, as this is a pre-requisite for the mounting to take place (ie not running the cells sequentially).如果您这样做,那么这将不起作用,因为这是安装发生的先决条件(即不按顺序运行单元)。 You can also try restarting Google Colab and this often fixes any strange errors.您也可以尝试重新启动 Google Colab,这通常会修复任何奇怪的错误。

Update:更新:

As you mentioned, the import error likely happens due to its configuration in the main file (ie it requires the file to be in the .py format to be imported just as import base_positioner ).正如您所提到的,导入错误可能是由于其在主文件中的配置而发生的(即,它要求文件为.py格式才能像import base_positioner一样导入)。

To import .ipynb extension file you will need to follow the following process: If you want to import A.ipynb in B.ipynb write要导入.ipynb扩展文件,您需要遵循以下过程: 如果要在B.ipynb中导入A.ipynb ,请写入

import import_ipynb
import A

The import_ipynb module can be installed via pip or any other relevant ways. import_ipynb模块可以通过 pip 或任何其他相关方式安装。

pip install import_ipynb

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError:Google Colab 上没有名为“nets”的模块 - ModuleNotFoundError: No module named 'nets' on Google Colab ModuleNotFoundError:Google Colab 中没有名为“pyaudio”的模块 - ModuleNotFoundError: No module named 'pyaudio' in Google Colab Google colab:ModuleNotFoundError:没有名为“pymorphy2”的模块 - Google colab : ModuleNotFoundError: No module named 'pymorphy2' ModuleNotFoundError:没有名为“google.colab”的模块 - Python - ModuleNotFoundError: No module named 'google.colab' - Python ModuleNotFoundError:没有名为“lanenet_model”的模块 - Google Colab - ModuleNotFoundError: No module named 'lanenet_model' - Google Colab Google Colab ModuleNotFoundError:没有名为“sklearn.externals.joblib”的模块 - Google Colab ModuleNotFoundError: No module named 'sklearn.externals.joblib' 在Google Colab中针对“注意ocr”修复“ ModuleNotFoundError:没有名为'fsns'的模块” - Fix “ModuleNotFoundError: No module named 'fsns'” in google colab for Attention ocr 如何解决 ModuleNotFoundError:没有名为“google.colab”的模块 - How to resolve ModuleNotFoundError: No module named 'google.colab' ModuleNotFoundError:Google Colab 中没有名为“tensorflow_data_validation”的模块 - ModuleNotFoundError: No module named 'tensorflow_data_validation' in Google Colab 在 google colab 中安装并运行 fairseq(ModuleNotFoundError:没有名为“fairseq”的模块) - install and run fairseq in google colab (ModuleNotFoundError: No module named 'fairseq')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM