Keras installation - python

I create an virtual environment in my conda named 'keras_ev' and install the keras in it
by
conda install keras
after that when i
activate keras_ev
jupyter notebook
the notebook does not show my keras_ev environment
and i fail to import the keras in my notebook.
Does anybody know how to fix this! Thank you

Try conda install ipykernel in your keras_ev environment. Then it should appear in your Jupyter notebook.
You can also install Python dependencies while using your Jupyter notebook. First, activate the environment keras_ev in another terminal tab. Then install your dependency using conda or pip (conda is recommended). It should be something like the text below.
In a new terminal:
source activate keras_ev
conda install *your_package*

In order for Keras to work you should first install one of its backends. If you don't install any of the backends it won't work, although it seems that it is installed. please refer to here.

If you have anaconda navigator installed, you can manually go there and click the environments panel (make sure to go to your preferred environment, there is a button in which you can select this)and add Keras. Then, if you run any application off of anaconda, it will automatically have Keras.

First You need to install Anaconda in your computer. Make sure, you
need to install anaconda for your python version.
After install that setup the anaconda environment and you need to
create new environment using anaconda prompt or command prompt or
terminal
conda create -n yourEnvName python=3.6
Now you can activate your environment using follwing command
activate yourEnvName
Now install keras using PIP. Before install keras you need to install tensorflow because keras run top of the tensorflow
pip install tensorflow
pip install keras

try this for activate the enviroment:
conda activate keras_ev
now, try to start the jupyter notebook using
jupyter notebook
or
jupyter lab

Related

Conda install packages from jupyter notebook

I have used !{sys.executable} -m pip install to install packages i want to use in my jupyter notebooks.
Now i also want to install some packaged by conda and use in the same notebooks.
This is the command i run and the error message
They ask us to create a separate conda environment. I am confused about this.
Do we need to create a new conda enviroment everytime we need new packages?
What is the correct way to install and access conda packages on jupyter python notebook?
You shouldn't in principle install from the jupyter notebook but from the terminal/cmd.
You can create an enviroment >conda create --name myenv
And activate it: >conda activate myenv
now everything you install will be restricted to myenv. for example conda install numpy
To use the packages in myenv in jupyter simply open jupyter with your enviroment active:
>conda activate myenv
>jupyter notebook
Note that you have to install jupyter in your enviroment too: conda install jupyter

Can't import NLTK into Jupyter Notebook

I'm pretty new to python, Jupyter notebook, Tensorflow, and that whole lot in general. I'm getting started with a machine learning project. I've gotten to the point where I want to import "nltk" into my thing. It doesn't work. I've installed nltk with pip, and conda, and everything, in my terminal. When I do it again in the notebook, it says I've already installed it, which is correct. But when I try to import it it gives me a ModuleNotFoundError:
I'm on a macbook, by the way. Any help?
Going forward you can follow these steps (through terminal) so that same issues don't crop up again.
Create a conda environment if it's not already done
conda create -n py3_env python=3.8
Get into the conda environment
conda activate py3_env
Install ipykernel
conda install ipykernel
Link the kernel to this conda env
ipython kernel install --user --name=py3_env
Deactivate the conda environment
conda deactivate
Now, when you open jupyter, you can select this kernel from the dropdown menu kernel >> Change kernel. Now, all the packages you've installed in this conda environment would be available in jupyter as well. E.g. you can install nltk in this environment in the following way:
conda activate py3_env
pip install nltk
conda deactivate

Trying to install a pip package in Anaconda

I'm trying to follow this tutorial:
https://learn.microsoft.com/en-us/azure/machine-learning/service/tutorial-data-prep
As part of this I'm trying to do a pip install of azureml as it's not available on conda. However doing a pip install will by default install it to my default python install, and not my conda install.
So I tried following the steps here:
https://conda.io/docs/user-guide/tasks/manage-environments.html#using-pip-in-an-environment
However after following these steps I then launch Jupyter notebook after activating myenv, navigate to the notebook, and try and run:
import azureml.dataprep as dprep
But get the error: ModuleNotFoundError: No module named 'azureml'
Also - I cannot tell if myenv is active in the notebook. The kernel simply says python3.
Be careful, when using pip in anaconda, it is possible that you are mixing pip and pip3.
Run which pip3 to be sure you are using the version that correspond to the virtual environment.
If you are using python3 in the environment, then pip will typically be the correct version to use. Do not use pip3 in that case.
This problem has been documented elsewhere on the web. The problem is that Jupyter notebooks itself only launches in the root environment by default. The simplest solution to getting it to launch for your env (e.g. myenv) is to install Jupyter within your env first. So from the Anaconda command prompt:
activate myenv
pip install jupyter
jupyter
Ps. Use source activate myenv for non-windows machines

Tensorflow is working in command prompt but not in Anaconda

Hi I have installed tensor flow in my 64 bit system using Window OS using pip3 install --upgrade tensorflow. Now I can able to work using tensorflow in my command prompt.
But while I'm trying to use it in my Anaconda ,Spyder (Python 2.7) I'm getting error message in import tensorflow as tf statement. It is saying No module named tensorflow. I'm new to python & tensorflow. Can you please help me to solve this issue?
Thanks
I solved the problem by uninstalling ipython and installing jupyter within the environment.
source activate myenv
conda uninstall ipython
conda install jupyter
Create a new conda environment. Your steps to create one with python=3.5 is correct. if you do not do this then you will have errors.
Once you have created that environment make sure you enter it: activate envName for example. You should get something like:
(envName) C:/> _
Then you should be able to install using pip install tensorflow
Once that has installed then run conda list to ensure that your conda env is happy that Tensorflow is installed. Then test it out by running
```
python
>>>import tensorflow as tf
```
Tensorflow on Windows will NOT work on anything but Python 3.5 at time of writing. Please remember to activate you conda environment by typing activate yourenvName and ensure that your environment is 3.5 when you create it.
pip3 install --upgrade tensorflow
installs tensorflow for Python3, and you want to use it in Python2. Try to
pip install --upgrade tensorflow
For more info read docs

Install tensorflow on Windows with anaconda

I am trying to install Tensorflow on my Windows PC. Since I have already install and used Anaconda on Python (3.5), I have followed the instructions https://www.tensorflow.org/versions/r0.8/get_started/os_setup.html#anaconda-environment-installation .
After the creation of the conda environment called tensorflow, I have tested my installation with:
$ python
Import tensorflow as tf
But I got the error :
ImportError: no module named 'tensorflow'
Does anyone know what I missed?
Thank you very much!
UPDATE: Since TensorFlow 0.12, we have published packages for Windows. You can install the CPU-only version with the following command:
C:\> pip install tensorflow
…and the GPU-accelerated version with:
C:\> pip install tensorflow-gpu
Note that you will need the 64-bit version of Python 3.5 installed for the above commands to work.
TensorFlow is not currently supported on Windows, and none of the official binary packages work on Windows. We are currently working on adding support for Windows, but this effort is in the early stages.
See the answers to this question for suggestions on how to run TensorFlow using Docker or Bash for Windows.
It looks like you need to activate the virtual environment that TensorFlow was installed in. When you activate the virtual environment, it will appear in parenthesis in your command prompt, like in the example tutorial:
$ source activate tensorflow
(tensorflow)$ # Your prompt should change
The source command only works on Linux/Mac as far as I'm aware, so for windows you'll have to follow the instructions here:
http://conda.pydata.org/docs/using/envs.html#change-environments-activate-deactivate
In general, the script file that handles the activation is location in [your_environment]/bin/activate if you're curious about what it does.
So basically the tensorflow files are installed inside this environment folder, and Python won't be able to find them unless this folder is added to the PATH where it searches for libraries, and this is essentially what activating the environment does!
The above provided steps will install the TensorFlow in your Windows System but still you might face problem in making it available in your Jupyter notebook - hence integrating steps from different places together to have a complete solution:
How to install Tensorflow in Anaconda environment on windows 10
1) Download and install Anaconda 3.6 (3.5 and above) in your system from Anaconda site.
2) Restart your system
3) Create virtual environment by following command:
conda create -n tensorflow
4) Activate the virtual environment
C:> activate tensorflow
(tensorflow)C:> # Your prompt should change
TensorFlow in anaconda
5) Following steps should start installing Tensorflow in virtual environment
(tensorflow)C:> conda install -c conda-forge tensorflow
6) Now you may enter in python and work on tensorflow
(tensorflow)C:> python
7) But if you like to work on Tensorflow on Jupyter notebook you need to setup the karnel for your virtual environment in following steps:
a) Install the ipython kernel module into your virtualenv
activate your virtualenv, if you haven't already
pip install ipykernel
b) Now run the kernel "self-install" script:
python -m ipykernel install --user --name=my-virtualenv-name
Replacing the --name parameter as appropriate. In my case it is tensorflow
c) You should now be able to see your kernel in the IPython notebook menu: Kernel -> Change kernel and be able so switch to it (you may need to refresh the page before it appears in the list). IPython will remember which kernel to use for that notebook from then on.
8) Test the tensorflow with following program you should see “Hello, TensorFlow!”
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
you can use pip to install tensorflow
Install python 3.5 x64
Install tensorflow using pip
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl
Install Visual C++ 2015 redistributable (x64 version) to be able to import tensorflow
Tensorflow installation using Conda:
Install Anaconda3-4.2.0 X64 (I ran into issue with latest release 4.3.0)
Upgrade conda version 4.2.9-->4.2.11 (again, ran into some issues with conda 4.2.9)
conda install conda=4.2.11
create environment
conda create -n tf python=3.5
activate tf
conda install -c conda-forge tensorflow
try installing tensorflow in conda
open anaconda prompt
and type this
conda install tensorflow
This worked for me (with spyder which is optional), typing in the anaconda prompt, on Windows 7:
conda create -n tensorflow pip python=3.5
conda activate tensorflow
pip install --ignore-installed --upgrade tensorflow
conda install spyder
spyder
To exit the virtual environment:
conda deactivate
To restart the virtual environment:
conda activate tensorflow
spyder

Categories

Resources