Cannot import name "is_sklearn_available" from "transformers.data" - python

I installed the package sentence_transformers via conda. It was successful; however, I cannot load them in jupyter notebook. I kept receiving the error as below. I have already upgraded all the relevant packages (sklearn, scipy, etc.) and I still receive the error.
from sentence_transformers import SentenceTransformer
ImportError: cannot import name 'is_sklearn_available' from 'transformers.data' (/Users/KK/opt/anaconda3/lib/python3.7/site-packages/transformers/data/__init__.py)
Any suggestions would be greatly appreciated.

I have faced this issue too. In my case, after restarting the jupyter kernel it worked without problems.
In my case, first I installed transformers 3.4.0, but had to downgrade to 3.1.0 due to a TF 2.1 compatibility issue. I downgraded without restarting the kernel and I got the same error message. After kernel restart, everything worked fine.

I faced this error as well. My mistake was that I was trying to import is_sklearn_available from transformers/data/init.py when I should have been importing it from transformers/file_utils.py
Please check your init.py files for a better picture.

Related

Using Matlab.engine and installing tensorflow at the same time

Currently I am working on a project with Jupyter Notebook in which I need to run a matlab script (.m) which includes a function that provides me with data which i try to solve with a tensorflow model afterwards. I can set up an environment that runs the matlab code an gives me the data and I can set up an environment that does the tensorflow thing but my problem is I can`t do it in the same environment.
Here is the setup and the problems. I am using matlab.engine which I installed like described here: https://de.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
To run my Jupyter Notebook I first navigate to the location where my python.exe and the matlab files are lying ("C:\Users\Philipp\AppData\Local\Programs\Python\Python37-32\Scripts"). If I try to run pip install tensorflow (in Anaconda Prompt) I got a lot of different errors like the following. Conda install works but even when it is installed i can`t import it.
ImportError: No module named 'tensorflow.core' or
ERROR: Could not find a version that satisfies the requirement tensorflow or just No module named 'tensorflow'
I searched for all those problems but nothing helped me. I think this has something to do with the directory I am working in and I know it is bad but I have no idea how to change that. The error also occurs in different environments.
Have you tried running !pip install tensorflow directly in Jupyter Notebook? It's a temporary workaround, but I am having the same problems and this one helped. Remember to comment it out after installation, so you wont re-run it by accident.
I found a solution to my problem. For this I needed a Jupyter Notebook and an external .py script that I design as a Flask. I can luckily run those in different environments. I past and request the data from the server by using "get" and "post".
If someone still has another idea to do all this in one JN, I would still be happy about answers.

Tensorflow import error in Jupyter Notebook

Initially, the code worked, but when I restart it again in notepad (Restart&Run All), I get an import error ImportError for tensorflow as follows:
cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model'
As a possible solution to the problem, uninstall the library on the command line in order to reinstall it. An attempt to do this via conda did not give any result (I got stuck at the solving environment stage: the pointer rotated, but then nothing happened). I achieved the solution using pip. And I got a second error - now with a different import:
cannot import name 'tf2' from 'tensorflow.python' (unknown location)
What should I do?
Actually, at first tensorflow "swore", after its" repair " - keras, but in the end the sequential execution of the commands pip uninstall tensorflow, pip uninstall keras and after them - the re-installation of modules helped.
There were experiments with a virtual environment, but these solutions turned out to be superfluous

Import Error when using VSCode with conda interpreter but not when importing in Conda

I'm trying to run a Python program in VSCode and it always stops in the first line
from sklearn.gaussian_process.kernels import WhiteKernel, RationalQuadratic, RBF, Matern, ExpSineSquared
The error it gives me is pretty big, I'll paste it at the end.
However, when when I open python in my conda terminal, I can import with no issues at all. Since I'm using the conda interpreter in VSCode, I don't understand what the issue is.
My Python version is 3.7.6, numpy 1.19.1, scipy 1.5.2, sklearn 0.23.2 and am working with Windows 10. I have already tried what the webpage mentioned suggested. And on the bottom left of VSCode it says that the interpreter is Python 3.7.6 64-bit ('base':conda).
Just tried, and I can't import numpy either, but can in conda with no problems. The python versions are the same. EDIT: The error message here asks me to be sure that the Numpy version is 1.18.1, instead of 1.19.1.
Exception has occurred: ImportError
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
The Python version is: Python3.7 from "C:\Users\jdion\anaconda3\python.exe"
The NumPy version is: "1.19.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: The specified module could not be found.
File "C:\Users\jdion\OneDrive\Ambiente de Trabalho\Tese\Code\The Sea Exploration Problem _aux.py", line 13, in
from sklearn.gaussian_process.kernels import WhiteKernel, RationalQuadratic, RBF, Matern, ExpSineSquared
I uninstalled both conda and all my Python versions and when I reinstalled Python 3.7.9 and selected it as the interpreter in VSCode there were no more issues. I think the problem was having too many Python versions, anaconda, pip, and I was probably installing and removing things in the wrong places.

Jupyter Notebooks MXNet import "RuntimeError: Cannot find the MXNet library."

I tried to import MXNet package in a Jupyter notebook and got an error which i could not fix after trying a lot of solutions.
Bottom of the stack trace looks like this:
What could be the cause of the issue here? I have Python 3.8 on PATH, MXNet 1.6.0 and Windows 10.
A lot of you would want to clarify if i imported the package in the first place. I did, as you can see. Numpy was imported with no issues, and mxnet did not, even though you can clearly see it present in my Lib->Site Packages.

tensorflow : ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package

When I try to run
import tensorflow as tf
at pycharm , then I got the error message
ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package
I refer to questions like question 1 and question 2 , they are just to recommend downgrade or reinstalling.
The particularity of this problem is :
cmd image When I run import tensorflow in cmd ,it works well.
The code of this project is correct because I 'have run it on other computer .And I use CONDA to keep the environment consistent.
I have checked the interpreter of pycharm and this project and it was correct .
How can I resolve it ? I have fight with this problems for 3 days.
I had the same problem with you. I found it is the pycharm to be blamed. In tensorflow version later than 2.0.0, the main functions of tensorflow is located in tensorflow_core instead of the folder tensorflow like tensorflow 1.x. When you use cmd, python can find these packages(by some methods), but the pycharm of old version cannot. So update your pycharm or use earlier versions of tensorflow might solve your problem.
Unable to import Keras(from TensorFlow 2.0) in PyCharm. these question said that PyCharm can recognises tensorflow 2.0.0b1)

Categories

Resources