Difficulty updating keras/tensorflow on mac - tensorflow

I am working on a jupyter notebook script which I used last year to train a neural network.
When I try to import the keras tokenizer:
from keras.preprocessing.text import Tokenizer
I receive this error
I have seen other posts which suggest that I need to update tensorflow. My anaconda environment tells me I have 1.13.1 installed. But when I try to update tensorflow-base to 1.15 in the anaconda navigator, I receive this error:
I can update tensorflow from my command line using:
conda install tensorflow=1.15.0
But this doesn't update tensorflow in my anaconda environment and the error persists in my notebook.
Any help would be much appreciated! As you can probably tell, I am a novice python user.

The error says some packages needed to update Tensorflow/Andaconda requires Python 3.11 or newer. Since not all of the error log can be seen however, I would upgrade to python 3.7 to be safe. You can download this from the official page: https://www.python.org/downloads/
If the problem persists, try using pip to update the packages(In bash) :
pip install tensorflow
pip install conda
If you get an error while using pip, try:
pip3 install tensorflow
pip3 install conda
This same method can be used to update keras:
pip install keras
or if that does not work:
pip3 install keras
If pip is not recognized at a command, Python 3.7 is not added to path. I do not have experience with macOS, but this article should go into enough depth.
https://realpython.com/add-python-to-path/#how-to-add-python-to-path-on-linux-and-macos

Related

Error when installing TensorFlow through pip

I'm following the instructions from https://www.tensorflow.org/install/pip#python-version-support to install tensorflow. I've used tensorflow before but for some reason, it has just stopped working. I'm using VS Code.
First, I check that pip and python are compatible:
python3 --version
python3 -m pip --version
I have Python 3.10.8, with pip 22.3.1 so it should be compatible. Then, I create a conda environment and activate it:
conda create --name tf python=3.9
conda activate tf
However, now when I try
pip install tensorflow
I get the error
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
How can I fix this? I also tried things in the past like installing tensorflow through Conda, but I get errors when importing tensorflow there.
Could you please try again by opening anaconda cmd propmt and run below code:
conda create --name tf_new python=3.10
conda activate tf_new
then install tensorflow using:
pip install tensorflow
Now open the VS code by selecting the same created VirEnv tf_new from Anaconda navigator.
In VScode, Open a new jupyter notebook file and run the below code by selecting the tf_new (Conda VirEnv) in kernel(from top right) .
import tensorflow as tf
tf.__version__
Output:
'2.11.0'

Why isn't tensorflow or pytorch recognized after I restart conda virtual environment?

Last night, I made a virtual environment and the only installs I made were as follows:
conda install jupyter
conda install notebook
pip install transformers
And I was able to run huggingface transformers perfectly, but today I reactivate my conda virtual environment and I'm met with this puzzling error:
And this is the runtime error
I even tried making a new virtual environment with the same depencies and today I got these errors upon performing pip install transformers
And this in jupyter notebook
HuggingFace Transformers need to be installed in conjunction to either Tensorflow or Pytorch. From the HuggingFace installation instructions:
First you need to install one of, or both, TensorFlow 2.0 and PyTorch.
So you should choose which machine learning platform you like more and install that too in your virtual environment.
For Tensorflow either pip install tensorflow or pip install tensorflow-gpu and for Pytorch pip install torch torchvision
For example, in a fresh environment, the following instructions should make your errors disappear (I'm assuming you have a GPU):
conda install jupyter
conda install notebook
pip install tensorflow-gpu
pip install transformers

Python cannot find Tensorflow module

With Python3.5, I try to use the 'tensorflow' module:
import tensorflow as tf
But.. it says No mudule named tensorflow
I just tried to download the module with pip3:
pip3 install --upgrade tensorflow-gpu
(I have all the requirements to run tensorflow with GPU support as described at tensorflow.org)
I've seen a similar question here ImportError: No module named tensorflow , here's a sum up of what's inside:
Make sure installation is correct via:
pip3 show tensorflow
You can optionally re-install it again using: pip install tensorflow==1.2.0 --ignore-installed
Make sure you're running the python code with Python 3.x, verify using: python --version
Make sure you install TF and run the script through the same user, avoid installing TF using sudo pip install... and running the code with python script.py

I am not able to update tensorflow installed with anaconda

I have been trying to update tensorflow from 1.2.1 to 1.3.
I did the following on my terminal:
pip3 install tensorflow --upgrade
After this, I tried checking the version
python3 -c 'import tensorflow as tf; print(tf.__version__)'
This outputs 1.2.1 but not 1.3.0
All this had been done in an anaconda environment.
Operating system: macOS Sierra
I would like to know how one can perform this update.
Thank you
The solution that I found was to install pip inside the conda environment and use that instance of pip to install the packages. Please refer here
The reason I got the above error was that the python3 and pip3 paths were different.
This became evident when I ran the below commands inside the conda environment.
which python3
/Users/SMBP/anaconda/envs/tensorflow/bin/python3
which pip3
/usr/local/bin/pip3
Also, I think it is better to use virtualenv and virtualenvwrapper if you wish to work with tensorflow as it is the recommended way.

tensorflow installation issue using anaconda

I am trying to install tensorflow using anaconda but followed the following approach and failed.
C:\>activate tensorflow
(tensorflow) C:\>conda create -n tensorflow
CondaValueError: Value error: prefix already exists: C:\Users\pirates\Anaconda3\
envs\tensorflow
(tensorflow) C:\>pip install --ignore-installed --upgrade https://storage.google
apis.com/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl
tensorflow-1.1.0-cp35-cp35m-win_amd64.whl is not a supported wheel on this platf
orm.
(tensorflow) C:\>
I am not able to install tensorflow with conda command .. what do I do?
I had installed anaconda 1.5 for python 3.6.0
Please somebody help with this. Thanks in advance.
It sounds to my as a python version incompatibility ,try to install python 3.5 and then run tensorflow installation again.