No module named tensor flow -- iPython notebook - python

I understand this may be an old question, but still I cannot find solution from off-the-shelf Q$A. Here is the problem:
I am following Udacity "Machine Learning" and its assignments, and need use iPythonNotebook & tensorflow. Details : https://github.com/Omarito2412/udacity-deeplearning
Assignment2 requires tensorflow. BTW, I already installed Anaconda,
already made tensorflow working on Pycharm on the same computer which is Macbook, but do not know how to make it work on iPythonNotebook environment.
The codes are quite simple, as follows:
import numpy as np
import tensorflow as tf
from six.moves import cPickle as pickle
from six.moves import range
and the error message is as follows:
ImportError Traceback (most recent call last)
<ipython-input-1-0970743dd90d> in <module>()
2 # before proceeding further.
3 import numpy as np
----> 4 import tensorflow as tf
5 from six.moves import cPickle as pickle
6 from six.moves import range
ImportError: No module named tensorflow
Thanks. Any suggestions ?
PS: I have this problem on two MacBooks, and both MacBooks run Pycharm+tensorflow well.

You should deactivate and re-activate the environment
source deactivate tensorflow
source activate tensorflow

After I tried Anaconda-installation (I was using the other installation methods, which are all shown in the link below)
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation
It worked ...
Further, on terminal activate tensorflow
>>> source activate tensorflow
before open iPython Notebook
>>> ipython notebook
At last, I have to restart my macbook to make it work....

i have missed tensorflow install (3) number below the list..
now i have solved
for anaconda install
for enviroment install
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation
for tensorflow install
https://github.com/conda-forge/tensorflow-feedstock

This is likely due to an anemic environment variable, one of the library path class. I don't know how iPythonNotebook denotes the libraries it will search for files (say, $LD_LIBRARY_PATH), but I believe that you have to find it (a list of paths to libraries) and add the root directory of TensorFlow.

More than likely either Tensorflow is not installed in the right Python environment of Conda or not installed at all. Follow the below steps:
$ conda create -n tensorflow python=3.5
Once that is done, need to activate that as below:
$ source activate tensorflow
Then when you open IPython Notebook or Spyder, it will recognize the Tensorflow.

Run python -m ipykernel install --user --name <Environment_Name>. This should add your environment to the jupyter kernel list.
Change the kernel using Kernel->Change Kernel option or New-><Environment_Name>.

Related

Can't I simply copy and paste a program from a Jupyter notebook to a file.py?

It's weird, I wrote a functioning program on a Jupyter notebook and I wanted to have it in a normal python file with VSCode aswell. However, while copying and pasting the exact same code that doesn't give me any troubles in Jupyter, I get the message from VSCode:
module 'keras.engine.base_layer' has no attribute 'BaseRandomLayer'
In the line
import tensorflow as tf
I am, of course, in the same environment (anaconda with python 3.9.7)
Tensorflow version: 2.8.0
Any ideas?
This could be due to the multiple versions of Tensorflow or mismatching version of Tensorflow with Keras or other dependencies.
You can create a new environment and install latest tensorflow using.
pip install tensorflow==2.9.0
You can import all the packages using Tensorflow using below lines.
import tensorflow
from tensorflow import keras

How to get librosa.display and matplotlib working in jupyter notebook with anaconda 3.6

I'm trying to get Librosa working with python.
Originally I had Python 2.7 installed, I wasn't able to get Librosa working with Python 2.7 so I installed Anaconda (which I've never used before) so that I could have a separate environment (to allow my old programs written in 2.7 to continue to work). I'm trying to use Jupyter notebook which I've also never used before and I finally managed to import Librosa after creating an Anaconda environment with Python 3.6, however I'm not able to import librosa.display
When I googled "importing Librosa.display" apparently I need to install matplotlib first, however importing matplotlib is failing and I'm not sure why. I think it might be failing due to importing PIL /pillow? however I've never specifically used that module before or had to install it separately when using matplotlib so I'm not sure why it's needed.
I tried reinstalling pillow using PIP install in the anaconda python3.6 environment that I created but it didn't work so now stuck and just wondering if anyone can help me?
for the import code as follows
import matplotlib
import librosa
import matplotlib.pyplot as plt
import librosa.display
The program gets stuck on "import matplotlib.pyplot as plt" and the error message I currently have is as follows (prior to reinstalling pillow it didn't work but the message was different):
C:\Users\sh\.conda\envs\signalprocess1\lib\site-packages\PIL\Image.py:130: RuntimeWarning: The _imaging extension was built for another version of Pillow or PIL:
Core version: 8.2.0
Pillow version: 8.1.2
warnings.warn(str(v), RuntimeWarning)
C:\Users\sh\.conda\envs\signalprocess1\lib\site-packages\matplotlib\mathtext.py in <module>()
25
26 import numpy as np
---> 27 from PIL import Image
28 from pyparsing import (
29 Combine, Empty, FollowedBy, Forward, Group, Literal, oneOf, OneOrMore,
C:\Users\sh\.conda\envs\signalprocess1\lib\site-packages\PIL\Image.py in <module>()
111 if __version__ != getattr(core, "PILLOW_VERSION", None):
112 raise ImportError(
--> 113 "The _imaging extension was built for another version of Pillow or PIL:\n"
114 f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
115 f"Pillow version: {__version__}"
ImportError: The _imaging extension was built for another version of Pillow or PIL:
Core version: 8.2.0
Pillow version: 8.1.2
Any help would be great. I don't need to use Jupyter I'm perfectly happy using IDLE if IDLE will work with Librosa and matplotlib through Python 3.6. All I want to do is get Librosa and Matplotlib working so I can analyse signals! I guess if I spend another couple of days on it I'll work it out eventually but it's very annoying spending all this time just trying to get the packages working before I even get to the signal analysis.
thanks!! :)
I'm not sure what I was doing wrong.....
however in the end I got librosa working with anaconda python 3.8 and jupyter on Windows 10 (64) as follows...
Uninstalled anaconda (possibly it wasn't necessary to uninstall it - not sure)
Uninstalled jupyter the best I could (still seemed to be some remnants associated with arcpy)
Installed miniconda the python 3.8 version
Created a new (separate) Conda environment which also used python 3.8
This was done by opening the Conda command prompt then typing......
conda create --name signalpro38 python=3.8
(note that signalpro38 is the name I gave the new environment)
activated the new environment by typing:
conda activate signalpro38
Installed:
matplotlib,
scipy,
numba,
numpy
then
jupyter
into the new environment (signalpro38)
by typing
conda install matplotlib
conda install scipy
etc.
Added the new anaconda environment to jupyter by following the instructions here:
https://medium.com/#nrk25693/how-to-add-your-conda-environment-to-your-jupyter-notebook-in-just-4-steps-abeab8b8d084
opened jupyter and created a new notebook (making sure to choose the name of the new environment signalpro38)
typed code into the new notebook, saved and ran it, to check that the commands
import matplotlib
and
import matplotlib.pyplot as plt
were working ok in jupyter
Closed jupyter and went back to the Conda command prompt (the signalpro38 environment that I had created was still activated)
then installed librosa using
pip install librosa
(note that "conda install librosa" didn't find librosa, however I imagine there is a way to install librosa using conda also)
opened jupyter again and the previously saved notebook file and added
import librosa
import librosa.display
all seems to be working well now! :)
Hopefully this will help someone else! most likely it will help me when I need to do this again one day! :p

no module named 'tensorflow' in mac

i have just install python, anaconda, tensorflow
and i was trying to do first test of tesorflow in jupyter notebook
but i doesn't work plz help me
Thank you
python version == 3.7.0
using macbook 2015
import tensorflow as tf
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-64156d691fe5> in <module>
----> 1 import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
i have already checked in terminal (pip3 list)
It already has tensorflow ,bu i have no idea why it doesn't work
There could be so many different reasons the import is not working, you need to give us more information.
what environment did you install tensorflow in (if at all)?
did you check to see if the environment had tensorflow installed through conda list?
why did you choose to pip3 install instead of conda install?
did you activate the environment when you started the notebook?
did you try uninstalling tensorflow and reinstalling it?
I suspect that when you installed using pip3 it installed to the default location and not to the conda environment, in general, if you are using anaconda to manage your packages and environments always use conda install where possible. And when listing packages, use conda list not pip list.

Error installing Tensorflow in Windows 7

I am trying to install Tensorflow on a Windows 7 laptop in order to use jupyter notebook to play around with the object detection notebook in Github. I am facing this error:
ImportError Traceback (most recent call
last) in ()
4 import sys
5 import tarfile
----> 6 import tensorflow as tf
7 import zipfile
8
ImportError: No module named tensorflow
I am getting the above error when I start the Jupyter Notebook from inside the Conda environment in Windows 7. I have installed Python 3.5.4 & within conda environment, tensorflow as well.
I am also getting ... not recognized as an internal/external... for $ command while giving $ python and sometimes also for pip3 I have included several file paths in Environment Variables. Can you please suggest me what to do. I am using the Conda env as I feel I have a problem in having Windows Service Pack 1.
Make sure your Tensorflow folder is somewhere that the environment will look, such as [Python install directory]/Lib/Site-packages
If you are using Anaconda to manage your installation, be aware that it is community supported and not officially supported by Google. Google has a detailed guide on how to install Tensorflow on Windows as well as how to validate the installation. Follow their steps carefully and be aware you may need to start the process over if you miss a step.
1) Make sure you start with a clean Conda Environment for Tensorflow. You will need to specifiy Python version 3.5. You can do this by running the command,
C:> conda create -n tensorflow python=3.5
2) Once the new Conda environmnet is created, activate it. This step is commonly overlooked.
C:> activate tensorflow
(tensorflow)C:> # The Conda environment may appear before the drive letter
3) With the Tensorflow environment active, issue the pip command to install the appropriate Tensorflow version. To keep things simple, I assume you will be installing the CPU version. If you need the GPU version, refer to the Google guide since there are other things you will need to do in order to set up the NVIDIA drivers.
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow
Note the flags included on the pip install command.
To make sure that Tensorflow is installed properly, validate the installation. Do this by double checking that the Tensorflow Conda environment is active and starting a python console. Once the console is running type the following sample program, suggested by Google's guide.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
If you are new to Tensorflow, this code may not make sense. What it does is import the Tensorflow library, assign a variable called "hello" to a Tensorflow constant tensor. Tensorflow is a library designed to operate on Tensor data objects. The next line initiates a Tensorflow session which loads all the data objects. The final line prints the output of Session.run() on the hello constant object. If everything is set up correctly you should see
Hello, TensorFlow!
output on the console. If you don't, check to common installation issues included in Google's Tensorflow install guide.

Error installing keras with pip in Python2.7 (Windows 7): numpy not found

I'm totally new using Python and I have to learn quickly because of my job. I have downloaded Python2.7.13 (and also the pip package. My next step was:
C:\Python27\pip install keras
And it finished saying that theano and anaconda2 were installed to and also was fine.
The problem came when I tried the following line:
C:\Python27\python
>>>from keras.models import Sequential
And I get the following message (after others that don't give error):
ImportError: No module named numpy
The fact is that I got out of python and try pip install numpy and it says that I have already have numpy installed and show me in which folder I have it. So I go to that folder and try:
C:\users\maca\anaconda2\lib\site-packages\numpy\python setup.py install
And that returns:
This is the wrong setup.py file to run
I'm totally new so I'm very lost about what my next step should be and how to fix it, 'cause I'm not familiarized with Python. I would thank any understandable help.
Thanks in advance.
It sounds like you have vanilla python installed in C:\Python27\ and Anaconda installed in C:\Users\Maca\Anaconda2. These are different. Anaconda is not an add-on to python, it is a distribution of python. Anaconda will have the math prerequisites, vanilla will not. You can install Keras on vanilla (it's hard), but it sounds like you want to use Anaconda. Then use only anaconda. Run:
activate root
You should then be using Anaconda and you can run:
pip install keras
Also, keras works on top of a backend so make sure you either have theano (pip install theano) or tensorflow.
Then, in the same console window, using Anaconda, run python and type from keras.models import Sequential. It should work.
From then on, you can access anaconda (as long as it was set up with this command enabled) with activate root. This will set python and related arguments to refer to Anaconda rather than the default C:\Python27.
EDIT: If in the future you are planning to use only anaconda, you can delete C:\Python27 from your path or even add Anaconda to it. To add anaconda to you path, look up environment variables in the start menu, go to the system environment variables, and find PATH. If you haven't uninstalled Python27 yet you'll need to remove C:\Python27\ from that path, and then you can add C:\Users\Maca\Anaconda2 anywhere (probably towards the end depending on how often you use python and how cluttered your path is).
You are already using Anaconda Python distribution so you should use conda package manager for installing keras: run conda install keras in your terminal. This will install keras and all the dependencies.

Categories

Resources