python -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('we love you'))"
Microsoft Visual C++ Redistributable is not installed, this may lead to the DLL load failure.
It can be downloaded at https://aka.ms/vs/16/release/vc_redist.x64.exe
Traceback (most recent call last):
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\transformers\utils\import_utils.py", line 1172, in _get_module
return importlib.import_module("." + module_name, self.__name__)
File "E:\Eprogramfiles\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\transformers\pipelines\__init__.py", line 44, in <module>
from .audio_classification import AudioClassificationPipeline
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\transformers\pipelines\audio_classification.py", line 21, in <
module>
from .base import PIPELINE_INIT_ARGS, Pipeline
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\transformers\pipelines\base.py", line 36, in <module>
from ..modelcard import ModelCard
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\transformers\modelcard.py", line 48, in <module>
from .training_args import ParallelMode
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\transformers\training_args.py", line 30, in <module>
from .trainer_utils import (
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\transformers\trainer_utils.py", line 47, in <module>
import tensorflow as tf
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
from tensorflow.python.eager import context
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
from tensorflow.python import pywrap_tfe
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 28, in <module>
self_check.preload_check()
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\tensorflow\python\platform\self_check.py", line 54, in preload
_check
raise ImportError(
ImportError: Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires that these DLLs be installed in a dire
ctory that is named in your %PATH% environment variable. You may install these DLLs by downloading "Microsoft C++ R
edistributable for Visual Studio 2015, 2017 and 2019" for your platform from this URL: https://support.microsoft.co
m/help/2977003/the-latest-supported-visual-c-downloads
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1039, in _handle_fromlist
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\transformers\utils\import_utils.py", line 1162, in __getattr__
module = self._get_module(self._class_to_module[name])
File "E:\Eprogramfiles\Anaconda3\lib\site-packages\transformers\utils\import_utils.py", line 1174, in _get_module
raise RuntimeError(
RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback)
:
Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires that these DLLs be installed in a directory that is named in your %PATH% environment variable. You may install these DLLs by downloading "Microsoft C++ Redistributable for Visual Studio 2015, 2017 and 2019" for your platform from this URL: https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads
PS E:\Eprogramfiles\Anaconda3\Scripts>
解決方法:把 msvcp140_1.dll 複製到path變量中某一個文件夾即可。
Jupyter Notebook:
E:\Eprogramfiles\Anaconda3\python.exe 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)
RuntimeError: Failed to import transformers.trainer because of the following error (look up to see its traceback):
Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires that these DLLs be installed in a directory that is named in your %PATH% environment variable. You may install these DLLs by downloading "Microsoft C++ Redistributable for Visual Studio 2015, 2017 and 2019" for your platform from this URL: https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads
I installed tensorflow2.0.0-alpha0 for Python 3.7.2 on Windows 7 SP1. It's importing fine in Jupyter notebook, but when I try to import it in IDLE or the Python interpreter invoked from the command line, I get this error message.
I copied msvcp140.dll from one of the subfolders in python37 and pasted it in the main python37 folder (which contains python, pythonw etc files). Now I am able to import Tensorflow in IDLE and python interpreter invoked from the command prompt.The problem I mentioned appears to be solved. But whether it is the correct solution or not I do not know. But so far there have been no problems.
==========================================
如何安裝transformers
1. 首先,需要安裝Python。建議安裝3.6及以上版本的Python。
2. 按照transformers官方文檔的要求,需要額外安裝PyTorch或TensorFlow。具體選擇哪一個取決於您的需求。建議先安裝PyTorch或TensorFlow,然後再安裝transformers。
3. 打開終端,輸入以下命令安裝transformers:
pip install transformers
4. 安裝完成後,您可以嘗試運行以下命令測試是否成功安裝:
python -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('we love you'))"
如果輸出結果爲:
[{'label': 'POSITIVE', 'score': 0.9998704795837402}]
則說明已經成功安裝並使用transformers進行了情感分析。
REF
https://www.5axxw.com/questions/simple/1lzxjc