Tensorflow version different in conda env & jupyter notebook - tensorflow

I created a conda env and installed tensorflow 1.4
pip install tensorflow==1.4
This installed, and from within the environment, when i type
import tensorflow as tf
tf.__version__
it prints '1.4.0'
Now, i open jupyter notebook from the same environment, and when i type the same in the notebook, it gives me 1.10.0
How is this possible? Jupyter notebook should take the same libraries within which it is running. How does it have a different version of tensorflow
And btw I'm concerned with this because i wanna use 1.4.0 in my notebook

These are the questions I ask myself in situations like this, and they usually resolve my issue:
Was the kernel of my notebook running while I pipped? Shut down and restart.
Are pip and conda sharing PATH, et cetera? I don't take it for granted that my pip is modifying my conda env. You can check with these commands.
Your conda env is created, but is it active? You list created envs with these, and you can activate/deactivate with these.
Besides checking all of these, where am I launching jupyter from? I like to install jupyter with a simply pip install jupyter and that could add jupyter to the command line globally. Anaconda navigator/command line reliably launches the jupyter that lives in your Anaconda distribution.

To add to Charles Landau:
You likely installed tensorflow in parallel with pip and with conda.
Within your env, just check with pip list tensorflow and conda list tensorflow. Most likely you will see two different versions.
To be consistent do:
pip unistall tensorflow to keep only one.

Related

Why isn't tensorflow or pytorch recognized after I restart conda virtual environment?

Last night, I made a virtual environment and the only installs I made were as follows:
conda install jupyter
conda install notebook
pip install transformers
And I was able to run huggingface transformers perfectly, but today I reactivate my conda virtual environment and I'm met with this puzzling error:
And this is the runtime error
I even tried making a new virtual environment with the same depencies and today I got these errors upon performing pip install transformers
And this in jupyter notebook
HuggingFace Transformers need to be installed in conjunction to either Tensorflow or Pytorch. From the HuggingFace installation instructions:
First you need to install one of, or both, TensorFlow 2.0 and PyTorch.
So you should choose which machine learning platform you like more and install that too in your virtual environment.
For Tensorflow either pip install tensorflow or pip install tensorflow-gpu and for Pytorch pip install torch torchvision
For example, in a fresh environment, the following instructions should make your errors disappear (I'm assuming you have a GPU):
conda install jupyter
conda install notebook
pip install tensorflow-gpu
pip install transformers

Tensorflow version in jupyter notebook does not match that in the conda env?

I build a conda env with jupyter notebook, tensorflow-gpu and other stuff in it from conda-forge, on ubuntu 21.10. I also did:
python -m ipykernel install --user --name=condaenvname
However when I select the env/kernel I get a conflict. After importing tensorflow as tf I get:
# what version of tensorflow is running in this env
print(tf.version.VERSION)
2.8.0
while when I do !conda list I get this:
tensorflow 2.6.2 cuda112py39h9333c2f_1 conda-forge
tensorflow-base 2.6.2 cuda112py39he9472f8_1 conda-forge
tensorflow-estimator 2.6.2 cuda112py39h9333c2f_1 conda-forge
tensorflow-gpu 2.6.2 cuda112py39h0bbbad9_1 conda-forge
How can this be? How can I get jupyter to use the correct tf version and all other packages in the env? I really don't want to rant because I know a lot of clever people are working hard on improving this, but I've read and worked on this for days, and can still not get a clear answer on how to get jupyter notebooks to call in the correct kernel and execute the correct package versions. Thx. J
I did finally find a solution to the problem. Jupyter/tensorflow/python actually go and find all packages on the system associated with that version of python, so it was finding packages in my own directories at
~/.local/lib/python3.9/site-packages
so erasing the site-packages directory and all of its contents, restarting the jupyter server solved all the problems. This is a very poor software setup, the whole basis of a conda env is to create a new environment, unpolluted and uninfluenced by other software packages on the base system. But apparently jupyter/python goes looking for all packages on the system, thus defeating the whole purpose of creating an environment in the first place!

tensorflow is only available in virtual env in anaconda

I installed tensorflow-gpu in anaconda3.
The steps I followed are:
conda create -n tensorflow pip python=3.6
source activate tensorflow
pip install tensorflow_gpu-1.8.0-cp36-cp36m-linux_x86_64.whl
After these steps, I find that if I use the python and ipython in anaconda3/bin, I can't import tensorflow (no module named tensorflow)
But If I activate the environment of tensorflow or I use the python and ipython in anaconda3/env/tensorflow/bin, I can import tensorflow.
And there is also no directory for tensorflow inanaconda3/lib/python3.6/site-package
Anyone knows why?
You created a conda environment and installed Tensorflow to that environment. Therefore you can only use Tensorflow inside that environment.
If you wish to use Tensorflow outside of an environment then don't activate the environment you created and just pip install Tensorflow.

How to connect tensoflow to jupyter notebook?

I have installed Anaconda with jupyter notebook in /home/serg/anaconda/bin and installed tensoflow in ./.local/lib/python3.5/site-packages/tensorflow. My operation system is Ubuntu 16.04.
Is it possible to use tensorflow in jupyter notebook via changing some configuration in anaconda or jupyter?
P.S.: I know it is possible for most python IDE, but I need to do it with jupyter notebook in anaconda.
Looks like you may have installed stuff in the wrong order.
I run TensorFlow in Jupyter notebook all the time, I don't get your issue? If you have installed Anaconda and it is active eg when you type python, you get the Anaconda version of python, you just install TensorFlow with Pip (following instructions at TF.. ) and the fire up jupyter notebook do your imports including TF and you should be off and going, nothing special required. If you did it in the wrong order, eg TF then Anaconda just make sure that Anaconda is your default interpeter (as above) and re-install TF with pip. If that does not seem to fix whatever issue you are having, post more info...
post your notebook info that tries to import TF?
I understood my problem: just used anaconda promts and installed tensoflow right here. Then I run jupyter notebook in anaconda promts and imported tensorflow.

Jupyter notebook can not import module installed in the same environment

I have created a virtual environment using conda and then I have installed tensorflow within this environment. I can import it when I run interactive python shell. However, I can not import the tensorflow module within jupyter notebook.
You need install Jupyter into same environment. Activate the environment with tensorflow and:
conda install jupyter
to make sure you use the corresponding jupyter start with:
python -m jupyter notebook
You probably have two installations of python on your box. When you run your notebook, run the following:
import sys
print(sys.path)
and then
import os
print(os.environ['PATH'])
print(os.environ['PYTHONPATH'])
Make sure they are pointing the location where you installed tensorflow. You can check where you installed tensorflow by running from the command line:
pip show -f tensorflow
or from the shell by running:
import tensorflow
tensorflow.__file__
As David said, you probably have two installation of python on you machine,
check sys.path from your environment in terminal and from your notebook, they should ideally point to your local environment.
To use jupyter notebook from your local environment install it and run kernel using
python -m jupyter notebook