Why can't tensorflow be imported? - python

I just installed Tensorflow, and am trying to run a test program in Python to validate the installation. When I run the program usually nothing happens. A couple times the Spyder IDE has crashed. Here is the test program:
print('test before')
import tensorflow as tf
print('test after')
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
Interestingly, all lines before importing tensorflow run, that is "test before" is printed. However, the program seems to run into trouble with importing tensorflow because "test after" is not printed. Why can't the program successfully import tensorflow?
Also, note that the tensorflow installation seems to have been successful because at the end it printed "Successfully installed tensorflow-1.7.0". And no errors appear when running the program. Usually if there is a problem when importing the package you get an error saying something like "[package] cannot be found". In this case the program just runs for a few seconds and then stops (or the IDE crashes) without returning an error. When running python3 -c 'import tensorflow' it gave the error Illegal instruction (core dumped).
Tensorflow version: 1.7.0
Python version: 3.5.2
using Spyder IDE
Operating system: ubuntu 16.04 LTS

It turns out that newer versions of TensorFlow use AVX instructions that are not supported on older CPUs. This problem was discussed in a GitHub issue and in an earlier Stack Overflow question. The solution was to downgrade TensorFlow to version 1.5, which I did using the following commands:
pip3 uninstall tensorflow
pip3 install tensorflow==1.5
After downgrading to 1.5 the test code worked.

Related

Tensorflow error " ImportError: DLL loaad failed with error code-1073741795"

Issue in importing TENSORFLOW(error code-1073741795 in jupyter notebook, Pycharm, Anaconda command line and in spyder. Howevery I am able to install successfully. But when I'm trying import then I am getting this error
"ImportError: DLL load failed with error code-1073741795".
I have install all the versions of VS redistributable.
I am using win 7 with 64 bit os. I tried to install on tensorflow on all the versions of python 3.6, 3.7
& 3.8. with different versions of tensorflow. Did anyone encountered with error code-1073741795???
ImportError: DLL load failed with error code-1073741795
Failed to load the native tensorflow runtime.
See https://www.tensorflow.org/install/errors
what does error code-1073741795 means?
How do we fix it.
I got an error like this when installing tensorflow. It was because tensorflow was not installed properly.
First, delete your current installed tensorflow completely.
Install Anaconda.
Make a new conda environment (this will help).
After creating a conda environment, activate it.
After activating, write: 'conda install tensorflow==1.15.0'
I am suggesting tensorflow 1.15.0 because I have found it more stable and better than any other version.
To test it is working properly, write:
python
This will activate python, then write:
import tensorflow as tf
print(tf.__version__)
You may get some warnings when importing tensorflow, but ignore the warnings, you will not get any errors. (if you get any error, comment)

How can I uninstall Tensorflow 2.0.0-alpha0?

I am using sublime text editor to run tensorflow commands using pythin 3.7. In particular I am trying to run: tf.enable_eager_execution() but I get the error:
AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'
I have checked my version of tensorflow using: print(tf.__version__) and the version is: 2.0.0-alpha0.
What's odd is that I have uninstalled tensorflow completely using pip3 uninstall tensorflow and I still have that version running.
From reading around I believe I cant run tf.enable_eager_execution() because of my tensorflow version and thats why I am trying to uninstall it. Ive also tried to explicitly call it using tensorflow.contrib.eager but still no luck.
TensorFlow 2.0 has eager execution by default. To disable eager execution use
tf.compat.v1.disable_eager_execution()

Python crashes when I import tensorflow

When I try to import tensorflow my python crashes. I tried uninstalling it and installing it again, but It isn't still working. Here is a picture of the command prompt when I try to import it.
I'm not too sure what the error is here.
try to pip list to see all packages
if no tensorflow seen then just pip install tensorflow
or print dir(tensorflow) to see functions
It seems you aren't executing anything but just importing the module.

ModuleNotFoundError: No module named 'tensorflow'?

I got this error in Jupyter Notebook.
this may duplicate post but no any proper answer found
Neither below links helped me to solve this.
No module named tensorflow in jupyter
No module named tensor flow -- iPython notebook
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-b88de1945047> in <module>()
1 get_ipython().magic('matplotlib inline')
2 import numpy as np
----> 3 import tensorflow as tf
4 from tensorflow.contrib import rnn
5 import data_loader
ModuleNotFoundError: No module named 'tensorflow'
B:S -
enter image description here
I faced the same problem at first. I realized that in the conda-->envs -->
tensorflow-->Scripts-->idle.exe, is the python 3.5.5 shell. Where you can import tensorflow without any problems. So, I chaged the directory as C:\Users\Temp\Anconda3..... and then activated and deactived the tensorflow once. In the next step I entered the python mode and import tensorflow as tf worked right.
I had the same problem and I think I've found the solution!
See, I had installed both CPU and GPU versions of Tensorflow at the same time which apparently is wrong. Then, I uninstalled the GPU version, it didn't work this time either. So I uninstalled both of them and reinstalled the CPU version. It's working now.
BTW I'm on Win10(1803) and python 3.6.5 (not using anaconda.)
You can execute the following instructions and command to solve the issue: (do not include inverted commas)
Open Anaconda Prompt
type: "create --name py3-TF2.0 python = 3"
press "y" to continue
After successful completion:
type "conda activate py3-TF2.0"
type "pip install matplotlib"
type "pip install tensorflow==2.1.0"
type "conda deactivate"
type "pip install ipykernel"
type "conda install nb_conda_kernels"
Now exit the Anaconda prompt and open the Anaconda Navigator application. Switch to "py3-TF2.0" from the base environment using the Environment tab. Install Jupyter in the specified environment.
After successful installation, open Jupyter notebook and switch to "py3-TF2.0" kernel using Kernel Tab.
You're good to go for using TensorFlow 2.
Make Sure you use Anaconda 2020.02 or lower version.
As new version does not support TensorFlow 2.

no module named tensorflow

I installed tensorflow CPU version in windows as mentined on their official page.
It got installed successfully but giving error while I import the library.
Output for pip freeze also shows it's present:
spyder==3.1.2
SQLAlchemy==1.1.5
statsmodels==0.6.1
sympy==1.0
tables==3.2.2
tensorflow==1.0.1
toolz==0.8.2
tornado==4.4.2
traitlets==4.3.1
Using anaconda.
If you have python 2.X installed along with a Python 3.X do pip(version) example; pip3 instead of pip. I had a similar problem so i had a look around and someone said do pip3.6.1 but it spewed out an error so a few trys later pip3 worked. If not idk whats happening

Categories