Reputation: 51
I am trying to run BertForSequenceClassification from within Google Colab. My notebook needs to import BertForSequenceClassification from modeling_readmission, but modeling_readmission.py itself contains an important statement that is failing.
from file_utils import cached_path
Other imports like torch work. I tried running
!pip install file_utils
in the previous cell, and it claims to be successfully installed, but the import fails. Another post suggests restarting the module. Did that, no help.
Ironically, you can pip install and do the import from the same cell, and you will get a "successful" installed (or " requirement satisfied") message followed by the error.
Requirement already satisfied: file_utils in /usr/local/lib/python3.7/dist-packages (0.0.1)
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-cd0910142da0> in <module>()
1 get_ipython().system('pip install file_utils')
----> 2 import file_utils
I did note that the successful import statement claims that file_utils is installed at
/usr/local/lib/python3.7/dist-packages (0.0.1),
and if you do an !ls on that folder you will indeed see a directory entitled 'file.utils-0.0.1.dist-info, inside of which are INSTALLER, LICENSE, METADATA, RECORD, REQUESTED top_level_txt, WHEEL. I should add that, as recommended in other stackoverflow posts, I also tried appending system paths using:
sys.path.append('./')
sys.path.append('/content/drive/My Drive/CAMLBERT/') #location of modeling_readmission.py
sys.path.append('/usr/local/lib/python3.7/dist-packages') # alleged location of file_utils
Despite looking through several similar stackoverflow posts on colab install failures, I'm totally at a loss. How do I get my Colab to recognize that file_utils has been installed? And how do I get this notebook, which needs to import from modeling_readmission, to run without needing a restart after file_utils is installed?
Upvotes: 0
Views: 595
Reputation: 51
I'm not sure this is a great answer, but it is a workaround. I simply copied the contents of file_utils.py into a folder and placed them in the main directory of my project. Things ran fine after that.
Upvotes: 0