Reputation: 351
This is my first post and I am new to coding, so please let me know if you need more information. I have been running some AI to generate artwork and it has been working, but when I reloaded it the python script won't work and it is now saying "No module named 'transformers'". Can anyone help me out? It was when I upgraded to Google Colab Pro that I started to encounter issues although I am not sure why that would make a difference.
ModuleNotFoundError
Upvotes: 34
Views: 165403
Reputation: 1
I encountered the same problem. I rectified this by:
pip install transformers torch
.Now set to go
Upvotes: 0
Reputation: 1156
These are some possible solutions
Run the following command
!pip install transformers
Or, if that doesn’t work, try
!pip3 install transformers
Please note the use of !
, as it is a shell command, and not a python script.
Click Runtime
> Disconnect and delete runtime
Then click Runtime
> Run all
Upvotes: 5
Reputation: 694
In addition to @chattershuts answer and based on a different answer on the usage of magic functions (the full post can be found here), I would recommend the usage of these magic functions.
Therefore, the command would be-
%pip install transformers
Upvotes: 0
Reputation: 549
Even after I used this command (pip install transformers) the terminal said,
ModuleNotFoundError: No module named 'transformers'
But this solved it, in vscode terminal:
python -m pip install transformers
Upvotes: 1
Reputation: 86
Sometimes your editor will confuse python interpreters.
Probably use
!python -m pip install transformers
Upvotes: 4
Reputation: 11
You need to check which environment you are installing the library in and which one you are using to run the cells. Perhaps this is the problem.
It's not very intuitive, and for some reason the notebook doesn't change the environment to the correct one automatically when switching
Even when you change the environment and run "!pip install transformers" in the cell, it will be installed in the originally selected environment
Upvotes: 1
Reputation: 1
if it does not work with pip, try installing it with anaconda: conda install -c conda-forge transformers
Upvotes: 0
Reputation: 6881
If the already installed package shows in !pip show transformers
but you still cannot import transformers
, try restarting Python kernel (runtime) using Jupyter Lab/Notebook (Google Colab) menu.
This worked for me in Google Colab's GPU (T4) instance after installing transformers
with pip
initially produced the above error message during import attempts.
Upvotes: 0
Reputation: 121
Assuming you are referring to the module here https://pypi.org/project/transformers/ you need to install transformers with pip
pip install transformers
Upvotes: 9
Reputation: 312
after you install transformers, make sure to import it , and import the Module youre gonna use
Upvotes: 0
Reputation: 503
Probably it is because you have not installed in your (new, since you've upgraded to colabs pro) session the library transformers. Try to run as first cell the following: !pip install transformers
(the "!" at the beginning of the instruction is needed to go into "terminal mode" ). This will download the transformers package into the session's environment.
Upvotes: 33