import tensorflow working in terminal but not in jupyter notebook - tensorflow

I used the following guide to install tensorflow-gpu - https://towardsdatascience.com/tensorflow-gpu-installation-made-easy-use-conda-instead-of-pip-52e5249374bc
I created a new environment and installed tensorflow-gpu using the command -
conda create --name tf_gpu tensorflow-gpu
If I activate the environment, start python in terminal, and import tensorflow from the terminal, it works.
BUT
When I activate the environment, run a jupyter notebook and type -
import tensorflow
I get module not found error. How do I resolve this?

Start Command Promt (CMD) as administrator (right click). Do not enter any environment yet.
Install Jupyter (and nb_conda as well as ipykernel) to get your environments listed: conda install jupyter nb_conda ipykernel
Activate the environment you want to add to jupyter kernel: conda activate myenv
Install ipykernel in the environment (do this for all envvironemnts you would like to add): conda install ipykernel
To start Jupyter, cd to root (cd .. until you are at C:) then type (does not need to be inside and env): Jupyter noteboook
You might need to confirm that it shall open in a web browser (I use chrome)
Once open in a browser navigate to the folder of your choice, then make a new python 3 file.
Once inside click Kernel -> Change kernel and select the conda env you would like
You should now be able to change kernel (env) within all conda environments that have ipykernel installed (step 4)

Related

ModuleNotFoundError: No module named 'tensorflow' error in vscode terminal while running fine in wsl

I installed tensorflow using conda in wsl, and now I'm using it through Jupyter notebook and it's working fine. I also write codes in vscode and then run it through wsl using python3 filename.py and it works fine too.
the problem is when I try to run the code using the 'running' option of vscode and then I get the error ModuleNotFoundError: No module named 'tensorflow' in terminal.
I checked my environments and I only have 'base' environment so the packages should be installed there and I also tried 'conda ...' in vscode terminal and it didn't recognize conda either.
what can be the problem with my vscode?
also I have to say that numpy and matplotlib packages are running fine using vscode itself but tensorflow and some other modules are not identified
You need to create a new virtual environment in anaconda to install Tensorflow and can access the Visual Studio code from the same virtual environment.
Open anaconda prompt and type below code to create virtual environment
conda create -n tf tensorflow
conda activate tf
install TensorFlow in that "tf" virtual environment
pip install tensorflow
launch VS code by selecting the same "tf" virtual environment in anaconda navigator.
Now, type the below code to check if TensorFlow installed successfully in VS code.
import tensorflow as tf
print(tf.__version__)
Likewise, you can install other required packages in the same virtual environment.
pip install <package-name>

How do you install a module in spyder anaconda?

I'm trying to run some code in Spyder Anaconda. I thought it would be as simple as importing it as seen in the code but I get an error message:
ModuleNotFoundError: No module named 'image_registration'
I know this means that image_registration isn't included in what Spyder already has but I cant quite figure out how to add it.
from image_registration import chi2_shift
from image_registration.fft_tools import shift
Add your Anaconda Scripts path (Default=C:\Users\userna**\Anaconda3\Scripts) to Environment Variables and open your command prompt and type
pip.exe install module_nameIn your case pip.exe install image_registration To install module image Registration
Please tryout the below steps in anaconda prompt
1. conda create -n myenv
2. activate myenv
3. pip install image_registration
4. conda install spyder
5. spyder
If you have already installed image_registration package in an environment you can activate that environment and try to open spyder from the activated environment.

How to make default environment as conda environment in Spyder

I have installed tensorflow in conda environment and managed to connect it to jupyter by installing nb_conda and its working. But in Spyder it still shows "tensorflow module name not found" (perhaps Spyder is not connected to the conda environment). I have two questions :
1. How to enable Spyder to connect with conda environment so that I can run tensorflow
2. How to change default environment from "root" in conda prompt to my own created environment.
Spyder runs in the conda enviroment in which it is installed. With Anaconda install, you get it installed in the base interpreter.
For TensorFlow, create a new conda enviroment.
Install tensorflow in it.
conda install tensorflow
Install Spyder in the same enviroment.
conda install spyder
Or, directly install tensorflow in the base interpreter. Open the Anaconda prompt and enter ,
( base ) $ conda install tensorflow

Unable to create process because python.exe & pythonw.exe under Conda environment MISSING/GONE

From [Anaconda installer archive], I install Anaconda3-4.2.0-Windows-x86_64.exe, I open a conda prompt. I create conda environment.
conda create -n keras_tensorflow_2 python=3.5
Activate it.
activate keras_tensorflow_2
Install Theano, Tensorflow & Keras.
conda install theano
pip install --ignore-installed --upgrade tensorflow
pip install keras
*Although here, theano is successfully installed but does not work. But that's a different matter.
Run python & test for tensorflow inside the conda prompt.
python
import tensorflow
No error. It works.
So now I want to open using Spyder.
If I directly open Spyder, and import tensorflow inside the IPython, error shows:
ImportError: No module named tensorflow
So what I did that work is
Open Anaconda Navigator
Anaconda Navigator>Environments. Click keras_tensorflow_2 environment. [Pic_1]
Anaconda Navigator>Home. At dropdown menu for "Applications on", choose tensorflow_2. Install Spyder. [Pic_2]
Then, open Spyder from Start Menu. Windows Security Alert pop up. Click Allow access. [Pic_3] . Test tensorflow, still not working.
So have to go back to Conda Prompt. Type
activate tensorflow_2
spyder
Conda prompt will automatically close and Spyder will automatically open. Import Tensorflow. Finally WORKS!
Up until this point, the folder Anaconda3>envs>tensorflow_2 still has python.exe and pythonw.exe as show here [Pic_4].
HOWEVER, once I close/restart Spyder, the folder Anaconda3>envs>tensorflow_2automatically has MISSING python.exe and pythonw.exe. [Pic_5] I don't know why this would happen. So I can no longer use this environment. When I tried to 'Open with IPython' through anaconda navigator [Pic_1], error:
Unable to create process using
'C:\Anaconda3\envs\keras_tensorflow_2\python.exe
C:\Anaconda3\envs\keras_tensorflow_2\Scripts\ipython-script.py -i'
And every time I want to use Tensorflow, I have to recreate the environment. Any advice please? Thank you.
All pictures available here: https://drive.google.com/open?id=0B6eS8bjSwwBLSzFRTFVHdG9zTTA
I found a way around it. Python.exe and Pythonw.exe still missing. Maybe it actually doesn't matter them being missing. I don't know.
Anyway, when inside conda prompt, if I navigate to my specific environment's Script, activate the environment and then run Spyder from there, it will work.
cd C:\Anaconda3\envs\keras_tensorflow_2\Scripts
activate keras_tensorflow_2
spyder
Reference: How to ensure that Spyder runs within a conda environment?

GraphLab Create Launcher Installation Error Windows: There was an error creating the "gl-env" conda environment

I received the following error when trying to install GraphLab Create on Windows.
There was a problem creating the "gl-env" conda environment. Restart GraphLab Create Launcher.
Any advice on how to fix this?
In order to solve the problem I had to slightly modify the
https://turi.com/download/install-graphlab-create-command-line.html.
procedure with the following changes:
Step 1: Download Anaconda2 v4.0.0
Step 2: Install Anaconda
Run Anaconda2 v4.0.0 installer.
Double-click the .exe file to install Anaconda and follow the instructions on the screen.
Step 3: Create conda environment
Create a new conda environment with Python 2.7.x
CD anaconda2/scripts/
conda install -n root _license
conda update pip
conda create -n gl-env python=2.7 anaconda=4.0.0
Activate the conda environment
activate gl-env
Step 4: Ensure pip version >= 7
Ensure pip is updated to the latest version
miniconda users may need to install pip first, using conda install pip
CD anaconda2/envs/gl-env/
conda install pip or conda update pip
Install your licensed copy of GraphLab Create
pip install --upgrade --no-cache-dir https://get.graphlab.com/GraphLab-Create/2.1/ your registered email address here/your product key here/GraphLab-Create-License.tar.gz
Step 6: Ensure installation of IPython and IPython Notebook
Install or update IPython and IPython Notebook
conda install ipython-notebook
Step 7: Start IPhyton Notebook
Start IPhyton from gl-env
ipython notebook
Use following command:
conda create -n gl-env python=2.7 anaconda
instead of:
conda create -n gl-env python=2.7 anaconda=4.0.0
Note: gl-env can be replaced by any name eg. gbl-env. It does not need to be gl-env only.
Later you can follow the steps from turi.com or the following reference:
Reference
It seems that the work around for this issue right now is to use the command line instructions to install GraphLab Create. Note that these instructions are only for people who have previously tried to install using the GraphLab Create Launcher. If you have not installed any GraphLab products, then you can start at Step 1 of the command line instructions:
Go to Control Panel > Programs > Programs and Features.
In this panel, uninstall all instances of "GraphLab Create Launcher".
Reboot.
Reinstall GraphLab Create using the command line method starting at "Option 1: Step 2: Ensure pip version >= 7": https://turi.com/download/install-graphlab-create-command-line.html.
GraphLab Installation Steps on Windows:
Go to turi.com → Hover over Coursera Students → Click on Academic Licenses → Register → Check your email
Download Anaconda2 v4.0.0
Install it
Open Anaconda Navigator
Create a GraphLab environment using create button at the bottom of the interface, select python version 2.7, name it "gl-env"
Environments tab → Create → Python version = 2.7 → gl-env
Sample Image
N.B: It may take some time
Then select gl-env and clik play button, some options will pop up, select terminal
gl-env → Play button → Terminal
Execute the following command
python -m pip install pip==9.0.1
8.Execute the following command replacingYour email and license that has been sent to your email:
pip install --upgrade --no-cache-dir https://get.graphlab.com/GraphLab-Create/2.1/your email/license/GraphLab-Create-License.tar.gz
Execute the following command
conda install ipython-notebook
Click on Open with python notebook on your gl-env play button from anaconda navigator
Now execute the following command on Jupyter notebook
graphlab.get_dependencies()
Then execute
import graphlab
Hopefully you are all set