Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow 1.15 impossible to use after update #3266

Closed
beachboy4545 opened this issue Dec 4, 2022 · 18 comments
Closed

Tensorflow 1.15 impossible to use after update #3266

beachboy4545 opened this issue Dec 4, 2022 · 18 comments
Labels

Comments

@beachboy4545
Copy link

Describe the current behavior
Hello, my research requires that I use tensorflow 1.15. I am no longer able to use:
!pip install tensorflow==1.15
because there is no distribution for said version on Python 3.8.

When I use :
!sudo update-alternatives --config python3
followed by:
!sudo apt install python3-pip
!python3 -m pip install --user --upgrade pip

Then when I use:
!pip3 install tensorflow==1.15

I receive the message:
"WARNING: The following packages were previously imported in this runtime:
[astor,google]
You must restart the runtime in order to use newly installed versions."

When I restart my runtime, I receive a message that my session has crashed and the app.log has many warnings of:
"| WARNING | /usr/bin/python3: No module named ipykernel_launcher"

Describe the expected behavior
I expect that I would be able to restart my runtime without any crashing occuring and that I would be able to run the rest of my code that involves tensorflow1.15

What web browser you are using
Google Chrome

Additional context
(https://colab.research.google.com/gist/beachboy4545/d84aa2f8202099fa6e645971ea26dd0f/runtime-crash-tf1-15.ipynb)

@mayankmalik-colab
Copy link
Contributor

Unfortunately, changing Python in Colab is not supported. As you know, tensorflow 1 doesn't support Python 3.8 . That being said, you can still use fallback version (python 3.7) for a few more days. For more details on how to use the fallback version - #3246 . However, please upgrade your notebooks to be compatible with Colab’s current runtime version.

@Atotem
Copy link

Atotem commented Dec 8, 2022

@mayankmalik-colab Hello, I was also using tf 1.15 because it is one of the requirements to run a repository I'm using for a project. But now I can't install it via !pip install tensorflow 1.15. This was my best solution due to GPU requirements, python version needed and the repo has to many files to start modifying each one by one to import tf correctly. It would be nice to have this functionality back.

@cperry-goog
Copy link

Sorry, nothing we can do on this, this is on Tensorflow's issue.

@Atotem
Copy link

Atotem commented Dec 13, 2022

Hey @beachboy4545 , I found a way. Apparently you can install conda in colab. But, you have to activate your environment every time you want to use it. Follow this code blocks and you will achieve it:

Before everything, set pythonpath to nothing so you don't have conflicts.

%env PYTHONPATH = # /env/python

First, you get miniconda (I'm using miniconda with python 3.8 version, but you can change it). You have to keep the path '/usr/local' to make it work. Otherwise, colab will not recognize conda.

!wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.12.0-Linux-x86_64.sh
!chmod +x Miniconda3-py38_4.12.0-Linux-x86_64.sh
!./Miniconda3-py38_4.12.0-Linux-x86_64.sh -b -f -p /usr/local
!conda update conda

Then, append this path to install packages.

import sys
sys.path.append('/usr/local/lib/python3.8/site-packages')

Create your virtual environment with python version that matches TensorFlow 1.15 (3.6)

!conda create -n myenv python=3.6

Install TensorFlow 1.15

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
pip install tensorflow==1.15

Run your python file. Remember to activate your virtual environment as suggested.

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
python3 /content/test.py

Observations: As I mentioned, you have to activate your environment every time you need TensorFlow 1.15. Also, this approach works if you want to run python files. In my case this works. I hope this can help you too. Best regards!

@licj1
Copy link

licj1 commented Jan 4, 2023

Hello,
Thanks for your guidance. I have built the virtual environment according to your instructions, and I installed the tensorflow-gpu==1.15, and set "export CUDA_VISIBLE_DEVICES="0" when running the command, but I found that the program didn't use GPU, I searched but didn't find the solution. Do you know the reason? Could you please help me solve this problem? Look forward to your reply soon. Thanks for your time!

@Atotem
Copy link

Atotem commented Jan 9, 2023

Hello @licj1,
Did you check if you're connected to GPU? (go to 'Edit'->'Notebook settings'->'Hardware accelerator'->'GPU or TPU').

@beachboy4545
Copy link
Author

@Atotem Your method worked like a charm!

It does seem I not only have to reactivate but also rebuild an environment to use it, however, this is a small price to pay to make Colab useful for me again.

Thank you!

@Rithvik1900
Copy link

@Atotem I have tried your method, like you said I have created new environment and installed tensorflow == 1.15, after installing it I have tried to check the version it is still showing tensorflow = 2.12.0

@Nasialink
Copy link

Hey @beachboy4545 , I found a way. Apparently you can install conda in colab. But, you have to activate your environment every time you want to use it. Follow this code blocks and you will achieve it:

Before everything, set pythonpath to nothing so you don't have conflicts.

%env PYTHONPATH = # /env/python

First, you get miniconda (I'm using miniconda with python 3.8 version, but you can change it). You have to keep the path '/usr/local' to make it work. Otherwise, colab will not recognize conda.

!wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.12.0-Linux-x86_64.sh
!chmod +x Miniconda3-py38_4.12.0-Linux-x86_64.sh
!./Miniconda3-py38_4.12.0-Linux-x86_64.sh -b -f -p /usr/local
!conda update conda

Then, append this path to install packages.

import sys
sys.path.append('/usr/local/lib/python3.8/site-packages')

Create your virtual environment with python version that matches TensorFlow 1.15 (3.6)

!conda create -n myenv python=3.6

Install TensorFlow 1.15

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
pip install tensorflow==1.15

Run your python file. Remember to activate your virtual environment as suggested.

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
python3 /content/test.py

Observations: As I mentioned, you have to activate your environment every time you need TensorFlow 1.15. Also, this approach works if you want to run python files. In my case this works. I hope this can help you too. Best regards!

dude u are a miracle maker

@Ankitkumar803
Copy link

@Atotem I have tried your method, like you said I have created new environment and installed tensorflow == 1.15, after installing it I have tried to check the version it is still showing tensorflow = 2.12.0

as mentioned by Atotem this only works for python files , so you can insert
import tensorflow as tf; print(tf.__version__) in test.py file and then you can see that it will show tensorflow == 1.15

@ariopri
Copy link

ariopri commented Jul 14, 2023

I cant find file test.py

@PrashantDixit0
Copy link

PrashantDixit0 commented Aug 28, 2023

Tensorflow 1.15 can be used inside colab by creating seperate conda environment and inside it installing tensorflow with following command

conda install tensorflow=1.15

@MrDBC
Copy link

MrDBC commented Sep 12, 2023

I cant find file test.py

@ariopri

u have to create that file, its not present by default
inside the file put this code:

import tensorflow as tf
print("TensorFlow version:", tf.version)

and then run this command in colab cell:

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
python3 /content/test.py

basically we are runny .py files in a virtual conda enviroment

if we try to print tensorflow version in a colab cell, it will print the latest version tf 2.x

@MrDBC
Copy link

MrDBC commented Sep 12, 2023

Hey @beachboy4545 , I found a way. Apparently you can install conda in colab. But, you have to activate your environment every time you want to use it. Follow this code blocks and you will achieve it:

Before everything, set pythonpath to nothing so you don't have conflicts.

%env PYTHONPATH = # /env/python

First, you get miniconda (I'm using miniconda with python 3.8 version, but you can change it). You have to keep the path '/usr/local' to make it work. Otherwise, colab will not recognize conda.

!wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.12.0-Linux-x86_64.sh
!chmod +x Miniconda3-py38_4.12.0-Linux-x86_64.sh
!./Miniconda3-py38_4.12.0-Linux-x86_64.sh -b -f -p /usr/local
!conda update conda

Then, append this path to install packages.

import sys
sys.path.append('/usr/local/lib/python3.8/site-packages')

Create your virtual environment with python version that matches TensorFlow 1.15 (3.6)

!conda create -n myenv python=3.6

Install TensorFlow 1.15

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
pip install tensorflow==1.15

Run your python file. Remember to activate your virtual environment as suggested.

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
python3 /content/test.py

Observations: As I mentioned, you have to activate your environment every time you need TensorFlow 1.15. Also, this approach works if you want to run python files. In my case this works. I hope this can help you too. Best regards!

from what i found out, we can only run one .py file at a time.
for example , i have 2 files: imports.py and preprocessing.py

i run the imports.py file, then when i try to run the 2nd file, it doesnt take the imports i did in the ist file into account
idk if its a problem only to me?

@IniasSomers
Copy link

Hello, Thanks for your guidance. I have built the virtual environment according to your instructions, and I installed the tensorflow-gpu==1.15, and set "export CUDA_VISIBLE_DEVICES="0" when running the command, but I found that the program didn't use GPU, I searched but didn't find the solution. Do you know the reason? Could you please help me solve this problem? Look forward to your reply soon. Thanks for your time!

Hello there! I am have the same problem that in the .py file in it can't access the gpu, did you find an solution for this? Thank you have a great day

@tosemfdk
Copy link

Hey @beachboy4545 , I found a way. Apparently you can install conda in colab. But, you have to activate your environment every time you want to use it. Follow this code blocks and you will achieve it:

Before everything, set pythonpath to nothing so you don't have conflicts.

%env PYTHONPATH = # /env/python

First, you get miniconda (I'm using miniconda with python 3.8 version, but you can change it). You have to keep the path '/usr/local' to make it work. Otherwise, colab will not recognize conda.

!wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.12.0-Linux-x86_64.sh
!chmod +x Miniconda3-py38_4.12.0-Linux-x86_64.sh
!./Miniconda3-py38_4.12.0-Linux-x86_64.sh -b -f -p /usr/local
!conda update conda

Then, append this path to install packages.

import sys
sys.path.append('/usr/local/lib/python3.8/site-packages')

Create your virtual environment with python version that matches TensorFlow 1.15 (3.6)

!conda create -n myenv python=3.6

Install TensorFlow 1.15

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
pip install tensorflow==1.15

Run your python file. Remember to activate your virtual environment as suggested.

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
python3 /content/test.py

Observations: As I mentioned, you have to activate your environment every time you need TensorFlow 1.15. Also, this approach works if you want to run python files. In my case this works. I hope this can help you too. Best regards!

You saved my life bro. thanks a lot!

@dummyuser-123
Copy link

Hey @beachboy4545 , I found a way. Apparently you can install conda in colab. But, you have to activate your environment every time you want to use it. Follow this code blocks and you will achieve it:
Before everything, set pythonpath to nothing so you don't have conflicts.

%env PYTHONPATH = # /env/python

First, you get miniconda (I'm using miniconda with python 3.8 version, but you can change it). You have to keep the path '/usr/local' to make it work. Otherwise, colab will not recognize conda.

!wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.12.0-Linux-x86_64.sh
!chmod +x Miniconda3-py38_4.12.0-Linux-x86_64.sh
!./Miniconda3-py38_4.12.0-Linux-x86_64.sh -b -f -p /usr/local
!conda update conda

Then, append this path to install packages.

import sys
sys.path.append('/usr/local/lib/python3.8/site-packages')

Create your virtual environment with python version that matches TensorFlow 1.15 (3.6)

!conda create -n myenv python=3.6

Install TensorFlow 1.15

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
pip install tensorflow==1.15

Run your python file. Remember to activate your virtual environment as suggested.

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
python3 /content/test.py

Observations: As I mentioned, you have to activate your environment every time you need TensorFlow 1.15. Also, this approach works if you want to run python files. In my case this works. I hope this can help you too. Best regards!

from what i found out, we can only run one .py file at a time. for example , i have 2 files: imports.py and preprocessing.py

i run the imports.py file, then when i try to run the 2nd file, it doesnt take the imports i did in the ist file into account idk if its a problem only to me?

True!! Did you find any solution. Actually I am running stylegan2 code in google colab and I am facing exact same error as run_training.py file contains other module files and they are not considering tf==1.15 instead they are considering as tf==2x.

@Salma1795
Copy link

Hey @beachboy4545 , I found a way. Apparently you can install conda in colab. But, you have to activate your environment every time you want to use it. Follow this code blocks and you will achieve it:

Before everything, set pythonpath to nothing so you don't have conflicts.

%env PYTHONPATH = # /env/python

First, you get miniconda (I'm using miniconda with python 3.8 version, but you can change it). You have to keep the path '/usr/local' to make it work. Otherwise, colab will not recognize conda.

!wget https://repo.anaconda.com/miniconda/Miniconda3-py38_4.12.0-Linux-x86_64.sh
!chmod +x Miniconda3-py38_4.12.0-Linux-x86_64.sh
!./Miniconda3-py38_4.12.0-Linux-x86_64.sh -b -f -p /usr/local
!conda update conda

Then, append this path to install packages.

import sys
sys.path.append('/usr/local/lib/python3.8/site-packages')

Create your virtual environment with python version that matches TensorFlow 1.15 (3.6)

!conda create -n myenv python=3.6

Install TensorFlow 1.15

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
pip install tensorflow==1.15

Run your python file. Remember to activate your virtual environment as suggested.

%%shell
eval "$(conda shell.bash hook)"
conda activate myenv
python3 /content/test.py

Observations: As I mentioned, you have to activate your environment every time you need TensorFlow 1.15. Also, this approach works if you want to run python files. In my case this works. I hope this can help you too. Best regards!

I followed all these steps, but when I check the python version it doesn't show 3.6.. How can I solve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests