tensorflow is not working on a conda environment - python

I created an environment on conda and installed the tensorflow on it, with following the instruction from here. I check the tensorflow version on my environment with pip list | grep tensorflow
and it returns tensorflow (1.3.0).
but when I want to check tensorflow with python with import tensorflow as tf I got the error:Failed to load the native TensorFlow runtime.
Any suggestion how to solve this issue? Thanks

fixed it by this command:
conda install -c https://conda.anaconda.org/jjhelmus tensorflow
from this post

Related

Tensorflow - The kernel appears to have died. It will restart automatically

I am reading "Hands-On Machine Learning with Scikit-Learn, Keras and Tensorflow" and installed Tensorflow 2 as follows:
$ python3 -m pip install --upgrade tensorflow
In the jupyter notebook I tried to import Tensorflow as follows:
import tensorflow as tf
But then I get the following error message:
The kernel appears to have died. It will restart automatically
I know there is a bunch of StackOverflow threads about this topic. I have read them all. Some of them are old, some are new. Most of them suggest to downgrade the Tensorflow version to 1.5. But when I do that I can not use some of the methods of the Keras API (e.g. load_data() could not be found).
Is there anyone who have found a solution for that?
The second version of the textbook is all about TensorFlow version 2 so you have to use TensorFlow version 2 to use code. if there is a problem get the first version of the textbook which uses TensorFlow 1.
But I suggest learning TensorFlow 2 as it is the latest version.
if you are using anaconda Try installing TensorFlow 2 in a new environment.
To create a new environment open anaconda prompt.
conda create -n envname python=3.6
and then activate the environment
activate envname
Now try installing TensorFlow 2 and other necessary modules
and check.
If it does not work the best solution is to use google colab(colab.research.google.com/).where you can do everything online, you can even have free GPU.

bert-serving-start giving error TypeError: cannot unpack non-iterable NoneType object - tried multiple paths to the model

I am trying to use BERT with bert-serving-start in python3.8 but it does not initialise and throws error:
TypeError: cannot unpack non-iterable NoneType object
This may have something to do with the path not being recognised but I followed the instructions as follows: https://github.com/hanxiao/bert-as-service#install
My folder is unzipped and entire model path is:
C:\Users\g\PycharmProjects\Project1\cased_L-12_H-768_A-12\cased_L-12_H-768_A-12
This occurs when running this in the command line as instructed.
bert-serving-start
-model_dir \Users\g\PycharmProjects\Project1\cased_L-12_H-768_A-12\cased_L-12_H-768_A-12 -num_worker=1
I don't know if this is a bug to report as it does say untested with the current Tensorflow but it may just be a mistake I made.
Was hoping someone could double check it's not me before submitting a bug report.
Short Answer
You are using too new a version of Tensorflow. BERT-as-a-Service works only with a TF version between 1.10.0 and 1.15.0. Once you install the old version of Tensorflow, this error would go away. Also, use the absolute path, instead of relative path for the model_dir directory.
Long Answer
If you are on the latest version of Python and hence pip, you wouldn't be able to get TF 1.x versions. Currently TF 2.3.0 is out there. The oldest version of TF pip can get for you is 2.1.0cr1. But you can do the following to get say v1.15.0 of Tensorflow:
Create a virtual environment with Python v3.7.6 that comes with old version of pip.
Activate the new virtual environment.
Install v1.15.0 of Tensorflow
Install Bert server in this virtual environment.
Start the Bert server
You don't have to install bert client in this virtual environment. You can continue using the bert client in the base environment. It will still work.
conda create -n test python=3.7.6
conda activate test
pip install tensorflow==1.15.0
pip install bert-serving-server
bert-serving-start -model_dir C:\Users\VHS\uncased_L-12_H-768_A-12\ -num_worker=2
I got this error with various versions including 1.15.0, 1.15.2, 1.15,3 but found it worked with 1.14.0, 1.15.4 and 1.15.5 when upgrading incrementally
Adding to the answer by #VHS, the following works (using tensorflow 1.13.0rc1).
conda create -n test python=3.7.6
conda activate test
pip install tensorflow==1.13.0rc1
pip install bert-serving-server
bert-serving-start -model_dir /path/to/pretrained/bert/uncased_L-12_H-768_A-12/ -num_worker=4
For me, installing frash env with tensorflow 1.11.0 did the trick,
also in the doc's https://github.com/google-research/bert it state they used 1.11.0
python 3.7.3 and tensorflow 1.15.0 works for me. be careful about the numpy version, my version is 1.18, too advanced will cause the same error

no module named keras after installing keras

I'm using anaconda ver 3, and I have installed python as well separately from anaconda. I installed python ver 2.7 and ver 3.6 from python website.
Now, I have installed keras from anaconda command prompt by using conda install keras. However, when I open jupyter notebook and write :
import keras
it says :
no module named keras
I also tried importing tensorflow but it gave me the same error
As far as i know, keras is a version of tensorflow. You should try installing tensorflow instead and then run
import tensorflow as tf
tf.__version__
if you get '2.1.0' or any 2., you should be all set!
EDIT1: Keras is part of tensorflow not a version (as pointed out in the comments).
EDIT2: The link below gives good details on environments activation/creation.
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
Okay so what I did is first updated anaconda by using :
conda update conda
and then I installed python :
conda install python=3.7
and finally I installed keras again :
conda install keras
And now I can import both packages of keras and tenserflow

Import Error on Keras : 'can not import name 'abs'

I am trying to use keras for image classification. I want to load an already trained model (VGG16) for my project. but when I run
from keras.applications.vgg16 import VGG16
I get an error.
ImportError: cannot import name 'abs'
I reinstalled both tensorflow and keras using :
pip install --ignore-installed --upgrade tensorflow
conda install -c conda-forge keras
since I have found some suggestions that reinstalling could help on here though it was related tfp not VGG16.
Could someone help me, please? Why I am getting this error and how could I fix it?
OS:windows
Tensorflow and keras installed on CPU
after all trying to install tensorflow and keras in a virtual environment solved the problem. Still, don't know why this problem existed in the first place. steps are taken:
conda create --name vgg16project python # you can name it other than vgg16project
activate vgg16project
then install other packages you need such as pandas, seaborn etc. then installing tensorflow and keras with pip
pip install --upgrade tensorflow
pip install --upgrade keras
simply solved it. I guess there must be a reason why it is recommended to use tensorflow and keras in a virtual environment.
I was having similar issue with keras cannot import abs. Tried updating and found tensorflow file was still in use.
Could not install packages due to an EnvironmentError: [WinError 32] The process
cannot access the file because it is being used by another process: 'c:\progra
m files (x86)\microsoft visual studio\shared\python36_64\Lib\site-packages\
\tensorflow\python\ops\gen_dataset_ops.py'
Consider using the --user option or check the permissions.
After uninstalling keras and tensorflow - I deleted the whole tensorflow folder and reinstalled both tensorflow 1.10 and keras. This resolved my issue.
I had the same issue and just uninstalled (and deleted) tensorflow.
After that I installed it again with:
pip install tensorflow-gpu==2.0.0-rc1
I tried something like three different versions before getting it to work.

pip: need to change name of package tensorflow-gpu to tensorflow

I'm trying to install tensorflow with gpu support into a conda environment
I use the command:
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-linux_x86_64.whl
When I look at the packages installed with conda list I wind up with a package called tensorflow-gpu.
You cannot even import this package because it has a '-' in it.
How can I change the name to 'tensorflow'?
Edit: I'm now thinking that there must be something more to this. Why would a major package in the deep learning community have this apparent problem. Hopefully, a tensorflow expert can answer. I'm following the directions for Ubuntu and Anaconda here: https://www.tensorflow.org/install/install_linux
When you install the tensorflow gpu version, Anaconda will show that you have installed tensorflow-gpu. The -gpu just indicates that it is a gpu version and is not a part of the name. You can still just import tensorflow and the gpu version will be found.
I had a similar problem which was quite frustrating. I started with recently built .whl file and tried to install.
pip install /home/ubuntu/xfer/tensorflow_gpu-1.2.1-cp27-none-linux_x86_64.whl
Command line testing:
pip show tensorflow
no package called tensorflow
pip show tensorflow-gpu
but there is a package tensorflow-gpu at version 1.2.1
However, running one line in python failed despite assurances that conda would substitute:
import tensorflow as tf
I then repeated the pip install of the .whl file with the --upgrade option:
pip install --upgrade /home/ubuntu/xfer/tensorflow_gpu-1.2.1-cp27-none-linux_x86_64.whl
And then the one line of python succeeded:
import tensorflow as tf
And in fact based on https://www.tensorflow.org/install/install_linux#run_a_short_tensorflow_program, one would then run a slightly longer program which also succeeds:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

Categories

Resources