'No module named 'transformers' - trouble importing Python library

I'm using Windows 10.

I have installed the transformers package.

py -m pip show transformers


Name: transformers
Version: 4.18.0
Summary: State-of-the-art Natural Language Processing for TensorFlow 2.0 and PyTorch
Home-page: https://github.com/huggingface/transformers
Author: Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Sam Shleifer, Patrick von Platen, Sylvain Gugger, Suraj Patil, Stas Bekman, Google AI Language Team Authors, Open AI team Authors, Facebook AI Authors, Carnegie Mellon University Authors
Author-email: [email protected]
License: Apache
Location: c:\users\polga\appdata\local\programs\python\python310\lib\site-packages
Requires: filelock, huggingface-hub, numpy, packaging, pyyaml, regex, requests, sacremoses, tokenizers, tqdm
Required-by:

However when I import it with import transformers I get the error:

ModuleNotFoundError: No module named 'transformers'

This happens wit both Spyder and Google Colab. However when I do import pandas in both environments the package is imported correctly. I'm using a new computer and this hadn't happened to me before. What could the difference in behaviour be due to?



Solution 1:[1]

Do you have python2 and python3?

If yes maybe try:

pip3 install transformers

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luca G