Tensorflow GPU - Spyder - python

I am having a problem with importing tensorflow GPU on spyder.
This is what I get when I type import tensorflow on iPython using Spyder 3 (on MacOS)
When I checked what packages I have within tensorflow I get this list, which I see that iPython, and Spyder are not included.
Also in anaconda, when I click on tensorflow in Environments, I have the option to open it with Python, with terminal, but not with iPython or Spyder (or Jupyter)
I would very much appreciate any help.
UPDATE 1:
Ok I managed to get Spyder on tensorflow's ENV but when I run the command 'import tensorflow' on iPython I get this error (when I run the same command on Python's tab everything seems to work just fine.

Finally I solved this mystery. If you have installed Spyder from the Anaconda, go to the Anaconda launcher. There go to environments, you will see two of them: root and tensorflow. The latter one is created due to the instructions by tensorflow.org. Just run all those instructions on the root, don't activate tensorflow environment, it will work. Everything will be available in spyder.

The instructions mentioned on the (https://www.tensorflow.org/install/install_windows) link do NOT work for the Ananconda/Spyder setups on windows. Having struggled through this for hours below is the easiest solution to get this working. Hope this helps!
Basically you do NOT need to create a seperate tensorflow environment if you want to run this on spyder. Use the below commands to install tensorflow on the ananconda client.
1) Open the Ananconda prompt from the installation folder in the start menu.
2) Run below commands:
conda install pyqt
conda install tensorflow

Spyder is picking up the default Anaconda Env, whereas you have tensorflow install in a separate environment tensorflow
To work with Spyder & tensorflow, install tensor flow and openssl in default ENV

I figured out how to get this working using the instruction on Tensorflow link. Once you create the tensorflow enviroment you can Spyder(Tensorflow) in your ananconda start menu folder. If you run your code by opening this the tensorflow should work.

Using the Anaconda Navigator:
It works for me in a different way:
As tensorflow is separately created environment, install spyder in tensorflow envirnment.
(Anaconda>Home>Applications on>tensorflow>spyder>install ... wait for installation to complete and ten launch)

I have seen another issue in anaconda. If you install Tensor flow in root or custom environment (like 'tensorflow') its not accessible from jupyter notebook or spyder. The best way to do this is to install it in the administrator mode. Follow these steps:
Open "Anaconda Prompt" as an administrator.
Verify the status on top written "Administrator: Anaconda Prompt"
DON'T Activate any of the environments, root or tensorflow.
Type in the command "pip install --ignore-installed --upgrade tensorflow-gpu" to install Tensorflow with GPU support.
To install Keras type "conda install -c conda-forge keras"
To verify installation, type 'python' and then inside python env. type 'import tensorflow as tf'. If all is well it will work without error.

I faced the same issue and solved by performing following steps in order.
Assuming that you have created conda environment, installed tensorflow and activated it and also installed spyder.
Check the executable python of your conda environment
>>import sys
>>sys.executable
Note the path of python executable.
Go to Spyder preferences and set the interpreter path to the one noted above.

Related

ModuleNotFoundError: No module named 'visualization' in jupyter notebook python

I follow the notes and practice Neural Networks on jupyter notebook python,
At first I'm having problem with import tensorflow as tf
and then I look up on youtube and created new environment called tf in Anaconda Navigator and install tensorflow and keras.
enter image description here
Next note that I follow is
**from visualization import draw_nn_graph**
when i use this code, it shows **ModuleNotFoundError: No module named visualization**
i open command prompt and type **pip install visualization** in Command Prompt and it says succesfully installed, but it still cannot run. I need help
Since you mentioned the command prompt in the comments, I assume that you are on Windows. What is happening here is that you have two separate Python installations: one "normal", directly installed on Windows, and the Anaconda one. When you ran the pip install command in the prompt, you installed the module for the normal version, but since Jupyter is using the Anaconda install it cannot find it.
This image shows you an example of this. The right window is my command prompt, and it does not know Python since I did not install it. However, I have Anaconda installed, and with it comes a tool called Anaconda Prompt. You can see it on the left, that one knows Python. You should have this Anaconda prompt as well. Search for it in the start menu, run your pip install there and your problem should be fixed.
the question solved by
!pip install visualization; in the Jupyter Notebook in environment called tf that I created

How to instal Python packages for Spyder

I am using the IDE called Spyder for learning Python.
I would like to know in how to go about in installing Python packages for Spyder?
step 1. First open Spyder and click Tools --> Open command prompt.
For more details click visit this link,
https://miamioh.instructure.com/courses/38817/pages/downloading-and-installing-packages
I am running Spyder 4.2.4 and for me following solution turned out to be working:
open tools-> preferences -> python interpreter
click 'use the following python interpreter'
point the location to local python installation, in my case : C:\Users\MYUSER\AppData\Local\Programs\Python\Python37\python.exe
Click OK and restart the kernel.
Now the pip started to work and I was able to import any package I previously installed on the cmd/python CLI.
Spyder is a package too, you can install packages using pip or conda, and spyder will access them using your python path in environment.
Spyder is not a package manager like conda,, but an IDE like jupyter notebook and VS Code.
For the latest versions of Spyder use this console
at right bottom
Note: Once you hit enter it may take some time to install and you can't see the progress until it finishes.
Else:
Open anaconda command prompt
Activate your environment: conda activate env-name
Install the package: conda install your-package-name
I have not checked if the ways described by people here before me work or not.
I am running Spyder 5.0.5, and for me below steps worked:
Step 1: Open anaconda prompt (I had my Spyder opened parallelly)
Step 2: write - "pip install package-name"
Note: I got my Spyder 5.0.5 up and running after installing the whole Anaconda Navigator 2.0.3.
I installed Basic Python IDLE(python 3.9)
As I used to Spyder. I installed a standalone Spyder from https://www.spyder-ide.org/
Then I faced problems for packages
I tried this one
pip install spyder spyder-terminal

How to add a conda environment in jupyter

I'm try to enable a keras environmnt into jupyter.
Using below commands I added the conda tf environment for Keras :
C:>conda create --name tf python=3.5
C:>activate tf (tf)
C:\Keras\Test>pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.4.0-cp35-cp35m-win_amd64.whl
Next I downloaded Keras-2.1.3-py2.py3-none-any.whl (from : https://repo.continuum.io/archive/)
And successfully installed it.
(tf) C:\Keras>pip install --ignore-installed --upgrade C:\Keras\Keras-2.1.3-py2.py3-none-any.whl
But then when i type
(tf) c:\Keras\Jupyter Notebook
.
I would have thought to be able to 'switch' to the tf keras environment.
When starting up the web browser
But all I see in below jupyter page is the python 3 environment which doesn't know of keras. So shouldn't I see a "tf" environment here as well?
from both environments i can start the jupyter notebook, but not sure if that should make a difference, both startups dont show tf, am i missing something here?. (in the picture i also show both conda consoles)
When i try to launch a notebook that makes use of keras.
Then this is the error i see like if it wasnt installed ?. (i'm sure it did though).
.
However a small test in python ran directly from the console
proves keras is installed and working
(but why not in jupyter??)
Well when i was in the (tf) environment made earlier and typed "conda list"
I got a fairly short list of installed packages (just tensorflow) about 26 packages.
Then I noted that jupyter package wasnt in this environment.
Not sure if it should i added it with
conda install jupyter
After a while (that command added about 8 Gig of python code...) it got installed.
With the message:
Enabling notebook extension jupyter-js-widgets/extension...
- Validating: ok
next i tried
(tf) C:\Keras>python -m ipykernel install --user --name tf --display-name "Python3 tensorflow"
with a message "Installed kernelspec tf in C:\Users\Peter\AppData\Roaming\jupyter\kernels\tf"
I'm not sure though if this is the proper solution, because would it
always be required to add 8Giga just to launch it in a webpage.
(seams overkill, but i just dont know if that's normal for conda-jupyter. (while jupyther was allready in the 'plain' python 3
enviroment. (or it was available to conda)...not sure i'm thinking
perhaps it be better if conda was part of jupyter but maybe its just
the otherway around.
Fundamentally the problem is usually rooted in the fact that the Jupyter kernels are disconnected from Jupyter's shell; in other words, the installer points to a different Python version than is being used in the notebook.
You might first try installing with conda.
conda install -c conda-forge keras
Otherwise you can try installing from within the notebook itself:
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install keras
As tempting as it might be... DO NOT DO:
# DON'T DO THIS
!pip install keras
Create kernel.json file in ~/local/share/jupyter/kernels/<YOUR_KERNEL_NAME/. Take an example for the content from:/usr/local/share/jupyter/kernels/python3/kernel.json
see: https://jupyter-client.readthedocs.io/en/stable/kernels.html
https://ipython.org/ipython-doc/3/development/kernels.html

Installing Tensorflow - not supported wheel

I have installed Python version 3.5 and 3.6 and anaconda.
The following error occures when trying to install tensorflow following the steps here
https://www.tensorflow.org/install/install_windows
unsing anaconda
(tensorflow) C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl
tensorflow-1.0.1-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform.
As I am new to Python, I do not know how to circumvent this probelm.
I am using Win10 with 64bit.
Thanks a lot and best,
Martin
I ran into the same difficulties with the same error. It seems to be that Python 3.6 isn't immediately supported and found a sort of workaround here (note that this involves installing Python 3.5 which I did not already have installed, I don't know if this should be done a different way if its already installed):
If you are using anaconda distribution, you can do the following to use python 3.5 on the new environment "tensorflow":
conda create --name tensorflow python=3.5
activate tensorflow
conda install jupyter
conda install scipy
pip install tensorflow
\# or
\# pip install tensorflow-gpu
It is important to add python=3.5 at the end of the first line, because it will install Python 3.5.
If you've already created the tensorflow environment (the conda create step), you'll have to delete it and start over. Otherwise, you'll run into an error "CondaValueError: Value error: prefix already exists: C:\[your environment location]" (If you run into the unsupported wheel error, then you probably created the environment already.)
To delete your previous environment, according to the Conda Cheat Sheet, you first deactivate from (tensor flow) if needed by calling deactivate, then call conda remove --prefix ~/bioenvcopy --all. For ~/bioenvcopy I believe you use the tensorflow environment path. The location can be found by calling conda info --envs (citing the cheat sheet once again). Mine, for example, was conda remove --prefix ~/Anaconda3/envs/tensorflow
I successfully used this work around on Windows 10.
This solution probably be obsolete when 3.6 is supported.
Creating the tensorflow env without the correct python version did not work for me. So I had to do the following, which worked...
>deactivate tensorflow # start by deactivating the existing tensorflow env
>conda env remove -n tensorflow # remove the env
>conda create -n tensorflow python=3.5
>activate tensorflow
i had the same problem in windows 10 and python 3.6
so i navigated to anaconda navigator ( just search anaconda navigator in start search).
in the Environment tab you can create/delete your environments.
just create an environment, name it tensorflow and choose python 3.5 as python version.
then you can activate tensorflow in your command line:
activate tensorflow
and install tensorflow with :
pip install tensorflow #or tensowrlow-gpu
I had the same problem after hours of searching, I found that to save yourself from installing error problem in tensorflow. The convenient way for installing tensorflow is by creating a virtual environment in Conda with python 3.5.2 and using Conda-forge. This is done by running this commands:
conda create -n tensorflow python=3.5.2
activate tensorflow
conda config --add channels conda-forge
conda install tensorflow
Try installing the 64-bit version of Python 3.6.8:
https://www.python.org/ftp/python/3.6.8/python-3.6.8-amd64.exe
I was getting the same error with the same OS and that's what fixed it. Apparently Tensorflow doesn't work on 32-bit Python even if your OS is 64-bit.
Try uninstalling everything (python, etc.) and try again using the cmd only, not git bash or PowerShell.
https://github.com/tensorflow/tensorflow/issues/9264
In Anaconda prompt, follow the instruction on Installing with Anaconda,
conda create -n tensorflow
activate tensorflow
Then the third step is a little different, try:
pip install tensorflow
This should work, good luck! If anything wrong happens, please let me know.

spyder/juypter not working after downgrading python

I had to download my python version from 3.5 to 3.4 because one of the packages I needed wasn't supported in 3.5. I downgraded the python version using the conda command prompt, and everything worked fine - got my package to install with all its dependencies and no conflicts. But now when I try to open Juypter notebook or Spyder, nothing happens. My IPython works just fine. I'm thinking maybe i have to downgrade Juypter and Spyder, but I'm not sure. Anyone have any ideas?
After a day of searching I finally figured it out.
I initially used
conda install python=3.4
Bad idea - ended up having to do a fresh install of anaconda to get spyder and juypter working again.
What ended up working is creating a separate environment.
conda create -n py34 python=3.4 anaconda
activate py34
... then install packages ...
This added spyder(py34), juypter(py34), and all its "py34 brothers and sisters" to my start menu. Using these new shortcuts/environment, I now have access to the packages I need by choosing the appropriate short cut. Yes, my start menu has extra python shortcuts now, but whatever - it works.
Just make sure Make sure you install the packages you're looking for before you close the anaconda console. Perfect for installing theano dependencies mingw and libpython.

Categories

Resources