Install TensorFlow with specific version on Anaconda - python

TensorFlow has multiple versions, if I want to install a specific version in Anaconda, which command should I use?

I find the existing answers unsatisfying, as the OP asked specifically about Anaconda but the answers are just pip installs.
You can list the available versions for install doing
conda search tensorflow-gpu
which should give you some output that looks like
Loading channels: done
# Name Version Build Channel
tensorflow-gpu 1.4.1 0 pkgs/main
tensorflow-gpu 1.5.0 0 pkgs/main
tensorflow-gpu 1.6.0 0 pkgs/main
tensorflow-gpu 1.7.0 0 pkgs/main
tensorflow-gpu 1.8.0 h7b35bdc_0 pkgs/main
tensorflow-gpu 1.9.0 hf154084_0 pkgs/main
tensorflow-gpu 1.10.0 hf154084_0 pkgs/main
tensorflow-gpu 1.11.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 1.12.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 1.13.1 h0d30ee6_0 pkgs/main
tensorflow-gpu 1.14.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 1.15.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 2.0.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 2.1.0 h0d30ee6_0 pkgs/main
tensorflow-gpu 2.2.0 h0d30ee6_0 pkgs/main
If you need to specify a particular channel, the -c/--channel option is your friend, for example:
conda search -c conda-forge tensorflow-gpu
Then you can select your version by passing it to the install command, for example:
conda install tensorflow-gpu==2.0.0
If you needed the channel option in your search, you should add the same option to the conda install command. Note this will work the same for tensorflow (i.e. not the GPU version), just change the package name accordingly.
YAML Configuration
If you use YAML environment configuration files, you can do the same thing:
# environment.yaml
name: my_conda_env
channels:
- conda-forge
dependencies:
- tensorflow-gpu=2.0.0
Create your environment with command:
conda env create -f environment.yaml
or if you change the version of an already created environment:
conda env update -f environment.yaml

This is probably the simplest way to do it:
pip install --ignore-installed --upgrade tensorflow==1.4
If you want to see all available versions, you can check out https://pypi.python.org/pypi/tensorflow/json
I would highly recommend you use virtualenv or conda to isolate your tensorflow installation, especially if you want to play-test different versions and the CPU/GPU versions.

I am assuming that you are using Windows, python3.5, and CPU version of tensorflow.
let's first create conda environment.
C:> conda create -n tensorflow python=3.5
C:> activate tensorflow
(tensorflow)C:> # Your prompt should change
After creating the conda environment successfully, issue the correct command to install the specific version. I will guide you through installing three different versions.
To install version r1.0
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl
To install version r1.3
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.3.0rc1-cp35-cp35m-win_amd64.whl
To install master version
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.0-cp35-cp35m-win_amd64.whl
let me know if this is what you are looking for

To install specific version of python, tensorflow while creating conda environment:
conda create -n python=3.6 tensorflow=1.12.0

I have a older project which has dependency to run on:
Python: 3.7
Tensorflow: 1.13.1
For this I create a virutal environment using anancoda like:
conda create -n tf python=3.7 tensorflow=1.13.1
// here more modules with specific version can be added
After that we to activate env:
conda activate tf
after this ouput was:
(tf) D:\ff\testM>
Environment changed from (base) --> (tf)
(base) D:\ff\testM>

I have a older project which has dependency to run on:
Python: 3.7
Tensorflow: 1.13.1
To create i used ananconda:
conda create -n tf python=3.7 tensorflow=1.13.1
// here more modules with specific version can be added
conda activate tf //Activate environment
(base) D:\ff\testM> --> (tf) D:\ff\testM>
// environment changes from base to tf

Related

Incompatibility issue when installing tensorflow in conda

I was trying to install tensorflow in a new conda environment, but I met an incompatibility issue.
First, I use conda search tensorflow-gpu -c conda-forge to search available packages, and the return is
Then, I use command conda create -n tf27 python=3.8 tensorflow-gpu=2.7.0 -c conda-forge to install version 2.7.0, but I met the error below
conda information:
You can check all available packages in anaconda by using the below code in the anaconda prompt:
conda list
To install TensorFlow in the anaconda environment:
conda install pip
#If you require the latest pip
pip install --upgrade pip
#To install current stable release of TensorFlow for CPU and GPU
pip install tensorflow
pip install tenosrflow-gpu
You can also specify the version you want to install as below:
pip install tensorflow==2.7
pip install tenosrflow-gpu==2.7
To install the latest version of TensorFlow
pip install --upgrade tensorflow
As a reference, please follow this document for installing TensorFlow in anaconda. Also check this Tested build configurations to find the compatible TensorFlow version for CPU and GPU support in your system.

conda list -f --json spyder creates huge load

I do use anaconda on an ubuntu 20.04 and since a week or so I have a problem with processes like
/home/csi/anaconda3/bin/python /home/csi/anaconda3/bin/conda list -f --json spyder
creating a huge load between 40 und 160. The number of processes is about 110.
I have been using 4 environments created by ananconda-navigator all of them are Python 3-Projects, none of them is called spyder. One is called spyder5.
I am using the activation of conda python with the delivered .bashrc-snippet.
:~$ conda list conda
# packages in environment at /home/csi/anaconda3:
#
# Name Version Build Channel
_anaconda_depends 2020.07 py38_0
anaconda custom py38_1
anaconda-client 1.9.0 py38h06a4308_0
anaconda-navigator 2.1.2 py38h06a4308_0
anaconda-project 0.10.2 pyhd3eb1b0_0
conda 4.11.0 py38h06a4308_0
conda-build 3.20.5 py38_1
conda-content-trust 0.1.1 pyhd3eb1b0_0
conda-env 2.6.0 1
conda-pack 0.6.0 pyhd3eb1b0_0
conda-package-handling 1.7.3 py38h27cfd23_1
conda-repo-cli 1.0.4 pyhd3eb1b0_0
conda-token 0.3.0 pyhd3eb1b0_0
conda-verify 3.4.2 py_1
The process starts automatically again after a while. So to work without that huge load I created a bash script trying to kill all those processes every ten seconds.
I did not try to uninstall anaconda3 and recreate all Environments. I will do this when I am upgrading the Ubuntu-Version in May anyway.
But does anyone have had an issue alike? Or does anyone know howto deactivate the periodically start of conda list? This is really annoying.
If you need more information I would be happy to provide them for you!
So after a while an update of conda fixed this issue. However, this was strange behaviour.
I did reinstall spyder via pip3 command of the anaconda installation. After that I updated anaconda and conda via conda command.
:~$ pip3 install --force-reinstall spyder
:~$ conda update anaconda
:~$ conda update conda
This fixed the issue of "conda list" processes but not the issue of the one process creating a huge load. However now the system is usable again.

Anaconda new environment with tensorflow 1.14 version

I have a conda env with tensorflow 2.2.0 But now I want to create a new env with tensorflow 1.14.0.
I used conda create --name tensorflow1_14 tensorflow-gpu==1.14.0 to create a new env.
But when I tried checking the tensorflow version in this env it still gives me 2.2.0
and when I use conda list it shows the tensorflow-gpu version as 1.14.0
Because of this I cannot use the tf 1.14.0 Where am I going wrong?
If someone is wondering what went wrong! here is the solution.
There was an overlap of pip and conda install. Steps followed:
conda uninstall tensorflow-gpu==2.2.0
pip uninstall tensorflow-gpu==2.2.0
conda install tensorflow-gpu==1.14.0

How to install pytorch in Anaconda with conda or pip?

I am trying to install pytorch in Anaconda to work with Python 3.5 in Windows. Following the instructions in pytorch.org I introduced the following code in Anaconda:
pip3 install torch torchvision
But the following error came in:
Command "python setup.py egg_info" failed with error code 1 in C:\Users\sluis\AppData\Local\Temp\pip-install-qmrvz7b9\torch\
By searching on the web I found out that it may be because of setuptools being out of date but I checked and have it updated. I also tried:
conda install -c peterjc123 pytorch cuda80
But the following error arise:
The following specifications were found to be in conflict:
- pytorch
Use "conda info <package>" to see the dependencies for each package.
I also tried to load the pytorch's tar.bz2 file which I download in the following website:
anaconda.org/peterjc123/pytorch/files
And then just do:
$ conda install filename.tar.bz2
But I got the following error:
Error: HTTPError: 404 Client Error: None for url: file:///C|/Users/sluis/pytorch-0.3.1-py36_cuda80_cudnn6he774522_2.tar.bz2: file:///C|/Users/sluis/pytorch-0.3.1-py36_cuda80_cudnn6he774522_2.tar.bz2
I am quite new to this programming world so I don't really know how to dig more on the errors. Anyone knows how to get pytorch installed?
Edit: As suggested in the comments I tried:
conda install pytorch torchivsion -c pytorch
And I got the following error:
Error: Packages missing in current win-64 channels:
- pytorch
- torchvision
I did:
anaconda search -t conda torchvision
And tried to install dericlk/torchvision using the following command:
conda install -c derickl torchvision
But I am getting the same error:
Error: Package missing in current win-64 channels:
- torchvision
I couldn't find any torchvisionpackages for win-64.
conda list is giving me the following:
# packages in environment at C:\Users\aaaa\AppData\Local\Continuum\Anaconda3\envs\torchenv2:
#
mkl-include 2018.0.2 1 anaconda
certifi 2016.2.28 py35_0
cffi 1.10.0 py35_0
cmake 3.6.3 vc14_0 [vc14]
openmp 2018.0.0 intel_8 intel
mkl 2017.0.3 0
numpy 1.13.1 py35_0
pip 10.0.0 <pip>
pip 9.0.1 py35_1
pycparser 2.18 py35_0
python 3.5.4 0
pyyaml 3.12 py35_0
setuptools 36.4.0 py35_1
typing 3.6.2 py35_0
vc 14 0
vs2015_runtime 14.0.25420 0
wheel 0.29.0 py35_0
wincertstore 0.2 py35_0
zlib 1.2.11 vc14_0 [vc14]
=======
Go to the official PyTorch.org and follow the steps accordingly.
Select your preferences and you will see an appropriate command below on the page.
If you don't have GPU in the system, set CUDA as None or CPU
Example command:
conda install pytorch-cpu torchvision-cpu -c pytorch
The following worked for me. First install MKL:
conda install -c anaconda mkl
After this, install pytorch and torchvision:
conda install -c pytorch pytorch torchvision
For windows python 3.6 and above without cuda
pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
Can you please try with below steps
conda create -n pytorch_env python=3.5
source activate pytorch_env
conda install -c soumith pytorch
python
> import torch
You can even find pytorch after you execute command conda list.
For linux, cuda9.0, python3.6:
pip3 install http://download.pytorch.org/whl/cu90/torch-0.3.1-cp36-cp36m-linux_x86_64.whl
pip3 install torchvision
For other cuda/python version: check website: https://ptorch.com/news/145.html
try updating the base conda package with the following command,then you can try reistalling it.
conda update --all
conda update -n base conda
For me it worked doing this:
Uninstall the previous version: go to C:\users\username\anaconda3 and run the anaconda-uninstall.exe
Install again anaconda
then run the following commands on the anaconda pompt:
conda create -n my_env python=2.7
conda activate my_env
start the gui app
conda install -c peterjc123 pytorch
anaconda-navigator
For Readers live in 2021/06/xx:
use pip3 install torch
As an update, now the Pytorch official site has the right version depending on your system:
https://pytorch.org/
I recommend using the official website for installation. Some of the previous awnsers may lead to a version that is not adequate.
After Activating conda environment
Use below command
python3 -m pip install torch torchvision
Example
(torchenv) ubuntu#user :~$ python3 -m pip install torch torchvision
Visit https://anaconda.org/pytorch/torchvision and you will find the solution
conda install -c pytorch torchvision
Try running:
conda install -c pytorch pytorch

Running Tensorflow in Jupyter Notebook

I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called tensorflow as follows
conda create -n tensorflow
Then installed the data science Python packages, like Pandas, NumPy, etc., inside it. I also installed TensorFlow and Keras there. Here is the list of packages in that environment
(tensorflow) SFOM00618927A:dl i854319$ conda list
# packages in environment at /Users/i854319/anaconda/envs/tensorflow:
#
appdirs 1.4.3 <pip>
appnope 0.1.0 py36_0
beautifulsoup4 4.5.3 py36_0
bleach 1.5.0 py36_0
cycler 0.10.0 py36_0
decorator 4.0.11 py36_0
entrypoints 0.2.2 py36_1
freetype 2.5.5 2
html5lib 0.999 py36_0
icu 54.1 0
ipykernel 4.5.2 py36_0
ipython 5.3.0 py36_0
ipython_genutils 0.2.0 py36_0
ipywidgets 6.0.0 py36_0
jinja2 2.9.5 py36_0
jsonschema 2.5.1 py36_0
jupyter 1.0.0 py36_3
jupyter_client 5.0.0 py36_0
jupyter_console 5.1.0 py36_0
jupyter_core 4.3.0 py36_0
Keras 2.0.2 <pip>
libpng 1.6.27 0
markupsafe 0.23 py36_2
matplotlib 2.0.0 np112py36_0
mistune 0.7.4 py36_0
mkl 2017.0.1 0
nbconvert 5.1.1 py36_0
nbformat 4.3.0 py36_0
notebook 4.4.1 py36_0
numpy 1.12.1 <pip>
numpy 1.12.1 py36_0
openssl 1.0.2k 1
packaging 16.8 <pip>
pandas 0.19.2 np112py36_1
pandocfilters 1.4.1 py36_0
path.py 10.1 py36_0
pexpect 4.2.1 py36_0
pickleshare 0.7.4 py36_0
pip 9.0.1 py36_1
prompt_toolkit 1.0.13 py36_0
protobuf 3.2.0 <pip>
ptyprocess 0.5.1 py36_0
pygments 2.2.0 py36_0
pyparsing 2.1.4 py36_0
pyparsing 2.2.0 <pip>
pyqt 5.6.0 py36_2
python 3.6.1 0
python-dateutil 2.6.0 py36_0
pytz 2017.2 py36_0
PyYAML 3.12 <pip>
pyzmq 16.0.2 py36_0
qt 5.6.2 0
qtconsole 4.3.0 py36_0
readline 6.2 2
scikit-learn 0.18.1 np112py36_1
scipy 0.19.0 np112py36_0
setuptools 34.3.3 <pip>
setuptools 27.2.0 py36_0
simplegeneric 0.8.1 py36_1
sip 4.18 py36_0
six 1.10.0 <pip>
six 1.10.0 py36_0
sqlite 3.13.0 0
tensorflow 1.0.1 <pip>
terminado 0.6 py36_0
testpath 0.3 py36_0
Theano 0.9.0 <pip>
tk 8.5.18 0
tornado 4.4.2 py36_0
traitlets 4.3.2 py36_0
wcwidth 0.1.7 py36_0
wheel 0.29.0 <pip>
wheel 0.29.0 py36_0
widgetsnbextension 2.0.0 py36_0
xz 5.2.2 1
zlib 1.2.8 3
(tensorflow) SFOM00618927A:dl i854319$
You can see that jupyter is also installed.
Now, when I open up the Python interpreter in this environment and I run the basic TensorFlow command, it all works fine. However, I wanted to do the same thing in the Jupyter notebook. So, I created a new directory (outside of this environment).
mkdir dl
In that, I activated tensorflow environment
SFOM00618927A:dl i854319$ source activate tensorflow
(tensorflow) SFOM00618927A:dl i854319$ conda list
And I can see the same list of packages in that.
Now, I open up a Jupyter notebook
SFOM00618927A:dl i854319$ source activate tensorflow
(tensorflow) SFOM00618927A:dl i854319$ jupyter notebook
It opens up a new notebook in the browser. But when I just import basic python libraries in that, like pandas, it says "no packages available". I am not sure why is that when the same environment has all those packages and in the same directory, if I use Python interpreter it shows all packages.
import pandas
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-d6ac987968b6> in <module>()
----> 1 import pandas
ModuleNotFoundError: No module named 'pandas'
Why jupyter notebook is not picking up these modules?
So, Jupyter notebook doesn't show env as the interpreter
I came up with your case. This is how I sort it out
Install Anaconda
Create a virtual environment - conda create -n tensorflow
Go inside your virtual environment - (on macOS/Linux:) source activate tensorflow (on Windows: activate tensorflow)
Inside that install tensorflow. You can install it using pip
Finish install
So then the next thing, when you launch it:
If you are not inside the virtual environment type - Source Activate Tensorflow
Then inside this again install your Jupiter notebook and Pandas libraries, because there can be some missing in this virtual environment
Inside the virtual environment just type:
pip install jupyter notebook
pip install pandas
Then you can launch jupyter notebook saying:
jupyter notebook
Select the correct terminal python 3 or 2
Then import those modules
I believe a short video showing all the details if you have Anaconda is the following for mac (it is very similar to windows users as well) just open Anaconda navigator and everything is just the same (almost!)
https://www.youtube.com/watch?v=gDzAm25CORk
Then go to jupyter notebook and code
!pip install tensorflow
Then
import tensorflow as tf
It work for me! :)
Install Anaconda
Run Anaconda command prompt
write "activate tensorflow" for windows
pip install tensorflow
pip install jupyter notebook
jupyter notebook.
Only this solution worked for me. Tried 7 8 solutions.
Using Windows platform.
install tensorflow by running these commands in anoconda shell or in console:
conda create -n tensorflow python=3.5
activate tensorflow
conda install pandas matplotlib jupyter notebook scipy scikit-learn
pip install tensorflow
close the console and reopen it and type these commands:
activate tensorflow
jupyter notebook
I have found a fairly simple way to do this.
Initially, through your Anaconda Prompt, you can follow the steps in this official Tensorflow site - here. You have to follow the steps as is, no deviation.
Later, you open the Anaconda Navigator. In Anaconda Navigator, go to Applications On --- section. Select the drop down list, after following above steps you must see an entry - tensorflow into it. Select tensorflow and let the environment load.
Then, select Jupyter Notebook in this new context, and install it, let the installation get over.
After that you can run the Jupyter notebook like the regular notebook in tensorflow environment.
I would suggest launching Jupyter lab/notebook from your base environment and selecting the right kernel.
How to add conda environment to jupyter lab should contains the info needed to add the kernel to your base environment.
Disclaimer : I asked the question in the topic I linked, but I feel it answers your problem too.
For Anaconda users in Windows 10 and those who recently updated Anaconda environment, TensorFlow may cause some issues to activate or initiate.
Here is the solution which I explored and which worked for me:
Uninstall current Anaconda environment and delete all the existing files associated with Anaconda from your C:\Users or where ever you installed it.
Download Anaconda (https://www.anaconda.com/download/?lang=en-us#windows)
While installing, check the "Add Anaconda to my PATH environment variable"
After installing, open the Anaconda command prompt to install TensorFlow using these steps:
Create a conda environment named tensorflow by invoking the following command:
conda create -n tensorflow python=3.5
(Use this command even if you are using python 3.6 because TensorFlow will get upgraded in the following steps)
Activate the conda environment by issuing the following command:
activate tensorflow
After this step, the command prompt will change to (tensorflow)
After activating, upgrade tensorflow using this command:
pip install --ignore-installed --upgrade
Now you have successfully installed the CPU version of TensorFlow.
Close the Anaconda command prompt and open it again and activate the tensorflow environment using 'activate tensorflow' command.
Inside the tensorflow environment, install the following libraries using the commands:
pip install jupyter
pip install keras
pip install pandas
pip install pandas-datareader
pip install matplotlib
pip install scipy
pip install sklearn
Now your tensorflow environment contains all the common libraries used in deep learning.
Congrats, these libraries will make you ready to build deep neural nets. If you need more libraries install using the same command 'pip install libraryname'
You will need to add a "kernel" for it.
Run your enviroment:
>activate tensorflow
Then add a kernel by command (after --name should follow your env. with tensorflow):
>python -m ipykernel install --user --name tensorflow --display-name "TensorFlow-GPU"
After that run jupyter notebook from your tensorflow env.
>jupyter notebook
And then you will see the following
enter image description here
Click on it and then in the notebook import packages. It will work out for sure.
It is better to create new environment with new name ($newenv):conda create -n $newenv tensorflow
Then by using anaconda navigator under environment tab you can find newenv in the middle column.
By clicking on the play button open terminal and type: activate tensorflow
Then install tensorflow inside the newenv by typing: pip install tensorflow
Now you have tensorflow inside the new environment so then install jupyter by typing: pip install jupyter notebook
Then just simply type: jupyter notebook to run the jupyter notebook.
Inside of the jupyter notebook type: import tensorflow as tf
To test the the tf you can use THIS LINK
Although it's a long time after this question is being asked since I was searching so much for the same problem and couldn't find the extant solutions helpful, I write what fixed my trouble for anyone with the same issue:
The point is, Jupyter should be installed in your virtual environment, meaning, after activating the tensorflow environment, run the following in the command prompt (in tensorflow virtual environment):
conda install jupyter
jupyter notebook
and then the jupyter will pop up.
I have to install it using condo's pip3. Just start jupyter-notebook and execute following
import sys
sys.executable
This will give you something like this
/home/<user>/anaconda3/bin/python
Now in a terminal execute the following (using pip3 from the above path where we found our python)
/home/<user>/anaconda3/bin/pip3 install tensorflow
This is basically installing the Tensorflow in the Conda environment using the Conda pip3 installer

Categories