I am working in anaconda environment
I used conda install tensorflow to install tensorflow
In the code I :
import tensorflow as tf
from tensorflow.python.data import Dataset
The first command passes but the second command does not (Import error)
I looked In the github of tensorflow and saw that the tensorflow.python.data module exists but probably changed
Is there a way to get Dataset class from the anaconda installation?
If not is there a workaround ?
Ilan
My mistake was that i used :
conda install tensorflow
rather than follow the instructions in the tensorflow site
Ilan
Related
I am new to TensorFlow and I received error with the third line below saying "ModuleNotFoundError: No module named 'keras'". The code is written in jupyternotebook launched from an anaconda virtual environment.
import tensorflow as tf
from tensorflow import keras
(x_train,y_train)=tf.keras.datasets.mnist.load_data()
I have no problem with importing tensorflow and the second line. I used anaconda navigator to install both tensorflow and keras. (I didn't set anaconda my default python version when installing anaconda, could that be a reason? )Thanks in advance.
this:
import tensorflow as tf
from transformers import BertTokenizer, TFBertForSequenceClassification
model = TFBertForSequenceClassification.from_pretrained("bert-base-uncased")
Outputs the following error:
ImportError:
TFBertForSequenceClassification requires the TensorFlow library but it was not found in your environment. Checkout the instructions on the
installation page: https://www.tensorflow.org/install and follow the ones that match your environment.
However it's not true I don't have the TensorFlow library imported.
> print(tf.__version__)
'2.7.0'
As this is to answer the question when Tensorflow is indeed installed and imported this can often be a problem in this case.
BERT requires the tensorflow-gpu package so you need to have installed the tensorflow-gpu package to do what you are attempting here.
IF you are in a notebook run:
!pip install tensorflow-gpu
Otherwise on the command line run:
pip install tensorflow-gpu
Hope this is helpful to others out there facing issues!
import tensorflow as tf
from transformers import BertTokenizer, TFBertForSequenceClassification
Worked with
Tensorflow-2.7.0
huggingface-hub-0.2.1
tokenizers-0.10.3
transformers-4.15.0
Python-3.7
Install Tensorflow and Transformers
!pip install tensorflow
!pip install transformers
I believe you are on MacOS. If so, installing the latest version of transformers (v4.21.1) should fix this issue. (I am also running M1 pro, if that helps).
For me the latest update was giving an error with incompatible checkpoint weight files, so I had to install transformers v4.2.2 which gave me the above error.
To fix it, you need to do an editable install: https://huggingface.co/docs/transformers/installation#installing-from-source
i.e.
git clone https://github.com/huggingface/transformers.git
cd transformers
pip install -e .
Before running the above code, make the following changes:
In transformers/setup.py Line 134, change to "tokenizers==0.6.0"
In transformers/src/transformers/file_utils.py Line 87, change "tensorflow" to "tensorflow-macos"
Finally, in transformers/src/transformers/dependency_versions_check.py comment out Line 41 ("# require_version_core(deps[pkg])"
For the final step, upgrade the tokenizers library to a newer version (say 0.12.1). You cant have the newer tokenizers library before installing the transformers package - it fails to build the wheel.
Reference: https://id2thomas.medium.com/apple-silicon-experiment-1-installing-huggingface-transformers-2e45392d3d0f
https://github.com/apple/tensorflow_macos/issues/144
Transformers requires Tensorflow version >= 2.3
To see the installed Tensorflow version, run the python script below:
import tensorflow as tf
print(tf.__version__)
If tensorflow version is actually too low, you may upgrade it.
For Tensorflow of CPU version,
run the command in a notebook,
!pip install tensorflow>=2.3
or run the command in a command window:
pip install tensorflow>=2.3
For Tensorflow of GPU version,
run the command in a notebook,
!pip install tensorflow-gpu>=2.3
or run the command in a command window,
pip install tensorflow-gpu>=2.3
I'm using python 3.8.2 , keras 2.3.1 and tensorflow 2.2.0rc4 .
just with the following code :
import keras
from keras.models import sequential
I have this error :
AttributeError: partially initialized module 'keras.backend' has no attribute 'eager' (most likely due to a circular import)
if I use :
import tensorflow
or
from tensorflow.keras import ....
new error :
AttributeError: partially initialized module 'tensorflow.python.framework.ops' has no attribute 'register_tensor_conversion_function' (most likely due to a circular import)
full traceback:
enter image description here
enter image description here
My suggestion is to reinstall the package. Sometimes this happens due to the installation problem.
Use the following code to do so
Uninstall tensorflow
pip uninstall tensorflow
Requires the latest pip
pip install --upgrade pip
To install keras as separate package
pip install Keras
Current stable release for CPU and GPU
pip install tensorflow
Try this and hope this helps you.
It's an install problem, most likely; K.eager was introduced in Keras 2.3.0 (and is included in Keras 2.3.1), so your Python interpreter is somehow reading code of 2.2.5 or earlier.
A possible culprit is an Anaconda mishap. First run conda uninstall keras. Then, in the anaconda3 directory, search "keras" and delete all results. Lastly, run conda install -c conda-forge keras, which should download version 2.3.1. You might need to run similar steps with TensorFlow (in fact, it's better you do, and first reinstall TensorFlow then Keras).
P.S., your code is probably from keras import Sequential, as sequential should error differently.
I am following the article https://www.analyticsvidhya.com/blog/2018/10/predicting-stock-price-machine-learningnd-deep-learning-techniques-python/ . After copy and paste the following code:
#importing required libraries
from sklearn.preprocessing import MinMaxScaler
from keras.models import Sequential
from keras.layers import Dense, Dropout, LSTM
#creating dataframe
data = df.sort_index(ascending=True, axis=0)
new_data = pd.DataFrame(index=range(0,len(df)),columns=['Date', 'Close'])
for i in range(0,len(data)):
new_data['Date'][i] = data['Date'][i]
new_data['Close'][i] = data['Close'][i]
...
I get an error: "No module named 'keras'. I search online and find I need to install keras module. In the article https://github.com/antoniosehk/keras-tensorflow-windows-installation , there is a step-by-step guide on how to install keras. However, it requires Nvida graphic card for GPU while I only have an integrated Intel graphic card. Therefore, I try to find another link at https://software.intel.com/en-us/articles/intel-optimization-for-tensorflow-installation-guide that works for Intel graphic card, so I install tensorflow as follows:
conda install tensorflow-mkl
During the installation, I can see one package is called keras-xxx, so I belive keras is also installed. But after the installation, when I try to run the code, I still get the error. Why?
Thanks
If you have CUDA supports GPU (NVIDEA Series), I strongly recommend you to install tensorflow-gpu from the aconda forge by conda command (not by pip) because the tensorflow-gpu needs a lot of requirments such as CUDA, CuDNN and etc that caused too hard to configurate all together correctly. if use the conda all the packages install together easily (without any tears!!!)
conda install -c anaconda tensorflow-gpu
but if you want to use cpu, you can easily install tensorflow by the pip or conda
I'm trying to use tensorflow-gpu. Using Anaconda, I installed the libraries and active both (tensorflow and tensorflow-gpu) I have also installed Keras in this anaconda environment as well
Next I launch Spider IDE within my Anaconda environment and run my py script, that is when I get the following error:
cannot import tensorflow - Import Error: cannot import name 'self_check'
I'm totally lost. Any recommendations?
Using Python 3.5
Thanks
pip install --upgrade tensorflow
or
you can uninstall the tensorflow and re-install it.