Error importing tensorflow on windows with anaconda navigator - python

I'm trying to import tensorflow and I have already tried everything and in the cmd prompt, I succeeded to install tensorflow with PIP.
But when I'm trying to import tensorflow in Python, I get the following error:
Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python
interpreter
from there.
I have tried everything on the internet, but nothing seems to fix it. I have Python version 3.7.1
What is the problem and more important: how can I fix this??

First, if you have already installed tensorflow with pip, trying to install it again with conda is a bad idea. Before running the conda command, first uninstall the pip version.
pip uninstall tensorflow
That is an odd error you are seeing. Try to specify the channel you are installing from. It is available from both the anaconda and conda-forge channels
conda isntall tensorflow --channel anaconda

Related

Tensorflow error ModuleNotFoundError: No module named 'tensorflow'

I'm having issues with running tensorflow.
Important! I have already looked through other threads - they didn't solve my problem.
I'm on a MAC.
It looks like it got installed, but when on Jupyter I'm running
import tensorflow as ft
I get the error
ModuleNotFoundError: No module named 'tensorflow'
What I tried:
In the beginning I tried installing it with python 3.6 - that didn't work as during the pip installation process it ended with a fail saying i need python >= 3.7
OK, I created a new envt:
conda create -n tensorflow python=3.9
pip install --ignore-installed --upgrade tensorflow
conda install tensorflow
all ran successfully.
I can run now
pip show tensorflow
it gives me
Name: tensorflow
Version: 2.11.0
However the error in Jupyter still remains.
I tried installing it on PyCharm - it runs well, but not in Jupyter.
PyCharm is using python v. 3.9 (same as my tensorflow env)
And if I check my python v. in Jupyter, it's also 3.9
I even tried restarting my laptop to see if maybe that would help, but no.
Please give me ideas if any, what else could work.
Many thanks!
I dont think this is related to tf itself, more likely related to the imports and the enviroment.
Things you can try:
Activate your tensorflow environment in Jupyter: "conda activate tensorflow"
Install tensorflow in the base environment: "conda install tensorflow"
Check your Jupyter environment: make sure that you are running it in the same environment where tensorflow is installed "conda info --envs"
Reinstall Jupyter: If none of the above steps work, you can try reinstalling Jupyter "conda deactivate" to exit the tensorflow environment, "conda install jupyter" and "conda activate tensorflow" again to activate the environment.

Error installing Tensorflow 2 on Windows 11: SSL Decryption Failed or Bad Record Mac

So I am having trouble installing Tensorflow on Windows 11. I'm using Anaconda with Python 3.7.0 and I'm trying to install Tensorflow 2.1.0. The problem I have is when I try to install tensorflow with conda install tensorflow or pip3 install tensorflow I get the following error every time after a few dependencies are installed:
The only thing I can think of is the internet connection is slow on my laptop, which has been the case ever since I upgraded to Windows 11. Is there anything I can do? When I tried to install an earlier version of Tensorflow (1.13.1) I finally got it to install after it got stuck on the MKL package. I just kept trying to install MKL individually until it installed. But when I try to upgrade to 2.1.0 I immediately get the above error before any dependencies are installed. Has anyone had this problem?
I have the same issue while trying to update conda using :
conda update conda
I notice the difference after my organisation updated the firewa
enter image description here
Set SSL verification off then update
set SSL_NO_VERIFY=1

Tensorflow pip install on mac with python3

I know this has been asked many times, I saw them tried to solve my problem but I can't, nothing works for me.
I have a mac m1, My os version is BigSur 11.5.1
My python3 version is 3.8.10
I have a project folder, which I created my env in there as atai_env
I ran pip upgrade, my pip version is current which is 21.3.1
I activated my env and ran pip install tensorflow which gives this error;
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
I saw some command as pip install tensorflow-macos so I tried it, it seems to install but at the end it gives this Failed to build h5py which I tried to install but failed again
Then I tried to ran pip command given here for python 3.8 -> https://www.tensorflow.org/install/pip and it gives below error;
tensorflow-2.7.0-cp38-cp38-macosx_10_11_x86_64.whl is not a supported wheel on this platform.
I am so sick of this :/ I tried to install other versions of python but it always fails. Can someone explain what should I do, I can't believe I spent more than 2 hours on this.
On the tensorflow install page, it seems I should only be running pip install tensorflow but that doesn't work
Ok, Nothing that I found on google helped. I started over, and decided to try python versions starting from 3.9 with decreasing versions. Finally this command just worked -> pip install tensorflow with python 3.7.9 It is so frustrating, cost me a few hours. I wasn't expecting it would be unstable like this. Anyway, if you happen to face it just try to use one of the version 7 even tho tensorflow says it works for 3.7 - 3.9
PS: I am sorry but this is really stupid, it is almost 2022 and we are working on AI with this framework comon :/
I have MacOS BigSur 11.6.1 running and just created a virtualenv with Python 3.8.12. Installing tensorflow works without any problems:
pip install tensorflow
pip install tensorflow 1 err | 8s | voice_assistant py
Collecting tensorflow
Downloading tensorflow-2.7.0-cp38-cp38-macosx_10_11_x86_64.whl (207.1 MB)
I could successfully install and run TensorFlow from my M1 MacBook Pro. Monterey 12.4. Here's what I did:
1. Install Homebrew first
How typical.
2. Install Anaconda via Homebrew
brew install anaconda
Installing Python is a mess and I know most tutorials will suggest to use pyenv as the version management tools. I tried that, but didn't work. What worked for me is Anaconda.
3. Download PyCharm
It's a GUI-friendly way to switch between Python versions and environments.
4. Set the Python interpreter inside PyCharm
Note that I use Conda Environment. Note also that the conda executable is inside /opt/homebrew/anaconda3/bin/conda.
5. Install tensorflow-macos from the PyCharm terminal
After doing this, you can import tensorflow as tf inside your .py files.
You can try upgrading the version of pip.

I can't install keras on tensorflow environment

I am using python 3.8 and I installed Tensorflow-gpu on it via command prompt. Now I am going to install keras on it, but I can't. I am using
conda activate tensorflow
conda install -c keras-gpu
but it fails.
I also tried from anaconda navigator. But whenever I try to add keras-gpu, it doesn't show anything. No packages come on pop-up window. When I try keras, it says that my python version is 3.8. Keras can't be installed. What can I do now? If there is a offline process to install keras on tensorflow environment, it will be helpful for me. So can you please help me?

Not able to update the version of tensorflow

I am facing the below error while running the code for LinearClassifier in tensorflow.
AttributeError: module 'tensorflow.python.estimator.estimator_lib' has no attribute 'LinearRegressor'
My current version for tensorflow is 1.2.1. I tried to update the version of the package from ANACONDA environment, its not showing for an upgrade.
I tried to upgrade it from command prompt by using below command, it is successfully updating the package however it is not reflecting to the actual library when I am using it.
pip install --upgrade tensorflow==1.3.0
FYI, I am using Jupyter Notebook and have created a separate environment for tensorflow.
Please let me know if I have missed anything.
If your command pip install --upgrade tensorflowcompiles, then your version of tensorflow should be the newest. However you should restart your notebook. Also, as you said that you are using anaconda. You can also install and upgrade tensorflow as follows:
conda install -c conda-forge tensorflow # to install
conda upgrade -c conda-forge tensorflow # to upgrade
That should work. Check if you are using any environment but you are not updating the tensorflow version within the environment.
Also, please restart the notebook after saving it and run the cells and try. That should work.
Verify in the notebook : run - print(tf.__version__). Please mark the answer if it resolves.

Categories