ImportError: No module named 'transformers'
Author: myh10307
Pull request: no
Labels: name: wontfix

## ❓ Questions & Help

<!-- A clear and concise description of the question. -->
I have installed transformers by "pip install transformers command"
However, when I tried to use it, it says no module. 



Comments:
When you enter the command "python" what is the output? and what environment are you using? linux/Windows/mac/etc?

Also, could you copy the exact output of "pip install transformers" so that we can see?

Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32

Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated.  Libraries may fail to load.  To activate this environment
please see https://conda.io/activation

Type "help", "copyright", "credits" or "license" for more information.
>>>

I am working on Windows10

If I activate the virtual environment, then warning is gone.

Requirement already satisfied: transformers in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (2.3.0)
Requirement already satisfied: sacremoses in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from transformers) (0.0.38)
Requirement already satisfied: tqdm in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from transformers) (4.32.1)
Requirement already satisfied: boto3 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from transformers) (1.10.49)
Requirement already satisfied: numpy in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from transformers) (1.16.4)
Requirement already satisfied: sentencepiece in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from transformers) (0.1.85)
Requirement already satisfied: requests in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from transformers) (2.22.0)
Requirement already satisfied: regex!=2019.12.17 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from transformers) (2020.1.8)
Requirement already satisfied: joblib in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from sacremoses->transformers) (0.13.2)
Requirement already satisfied: click in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from sacremoses->transformers) (7.0)
Requirement already satisfied: six in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from sacremoses->transformers) (1.12.0)
Requirement already satisfied: s3transfer<0.3.0,>=0.2.0 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from boto3->transformers) (0.2.1)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from boto3->transformers) (0.9.4)
Requirement already satisfied: botocore<1.14.0,>=1.13.49 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from boto3->transformers) (1.13.49)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from requests->transformers) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from requests->transformers) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from requests->transformers) (1.24.2)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from requests->transformers) (2019.6.16)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1; python_version >= "2.7" in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from botocore<1.14.0,>=1.13.49->boto3->transformers) (2.8.0)
Requirement already satisfied: docutils<0.16,>=0.10 in c:\users\john\miniconda3\envs\my_bert\lib\site-packages (from botocore<1.14.0,>=1.13.49->boto3->transformers) (0.14)






I'm not familiar with Conda, have you tried working with it via the native environment i.e. don't use conda so you can see if its conda thats causing this problem?

My first thoughts is that the pip installer is installing the module correctly, but the python interpreter is pointed to a different location. This usually happens on OSX when I call "pip transformers" which installs under python 2.7 but when I use Python3 the module is missing. 

Well, you have to activate the environment, then install pytorch/transformers, and then (still in the activated env) run your Python code. It is clear from your problem that you are not running the code where you installed the libraries.

If you really can't figure it out, you can try to install with `python -m pip install transforlers` instead of `pip install`. That will ensure that the same `python` executable is used.

Actually, I have installed transformers in that env.  I just did it one more time as you suggested on.

C:\Users\John\Desktop\python\data_analysis\disaster>activate my_bert

(my_bert) C:\Users\John\Desktop\python\data_analysis\disaster>python -m pip install transformers

But, still, I got an error message from jupyter notebook when I imported transformers.

ImportError                               Traceback (most recent call last)
<ipython-input-1-279c49635b32> in <module>()
----> 1 import transformers

ImportError: No module named 'transformers'

Then you are not launching jupyter from the same environment/python installation as where you installed transformers.

You could write the command `!which pip` in your jupyter notebook to make sure you're using the correct environment, followed by `!pip list` to make sure ` transformers` is correctly installed.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.


Have you solved the problem

If your python version is 3.x try using "_pip3 install transformers_".

> If your python version is 3.x try using "_pip3 install transformers_".

Not necessarily. Depends on your environment/OS. 

When I run `pip list` I see 

> transformers                  4.8.2

But I'm still getting "ModuleNotFoundError: No module named 'transformers'"

Discrepancy between pip and python. Can you also see transformers when running python -m pip list? 

That was the issue. I had to install everything with `python -m pip` rather than default conda pip.

> I'm not familiar with Conda, have you tried working with it via the native environment i.e. don't use conda so you can see if its conda thats causing this problem?
> 
> My first thoughts is that the pip installer is installing the module correctly, but the python interpreter is pointed to a different location. This usually happens on OSX when I call "pip transformers" which installs under python 2.7 but when I use Python3 the module is missing.

I am currently having this problem when running on OSX. What did you do to fix this?

@austinbyersking  `pip3 install transformers` worked for me on macOS. I suggest you create an environment in `conda` and then install using `pip3`

I have this problem with `jupyter lab`. My OS is Windows 10 and python 3.8.8.

I can use `transformers` in my python interpreter but not in `jupyter lab`, of course I'm in the same virtual environment where transformers is installed with pip.

`pip list`, ` pip freeze` or `python -m pip list` all show `transformers 4.16.2`

Similar issue as @looninho except that my OS is Ubuntu 18.04 and python 3.8.0. The fix that worked for me was to install transformers with sudo privilege (sudo pip install transformers). I guess using --user would also do the same. And also uninstall conda transformer installation, if any.

On ubuntu 20.04 with conda env it work after I closed the terminal and in a new terminal i have activated again the env: 
`conda activate colab-script`

> Well, you have to activate the environment, then install pytorch/transformers, and then (still in the activated env) run your Python code. It is clear from your problem that you are not running the code where you installed the libraries.
> 
> If you really can't figure it out, you can try to install with `python -m pip install transforlers` instead of `pip install`. That will ensure that the same `python` executable is used.

i meet same problem and this advise solved it. Thank you.

> 

I have the exact same issue. Did you solve yours?

Same here, did you solve?

I had this issue, I fixed it by running the following code in conda terminal : 
conda install -c conda-forge transformers