View This Site In Your Own Language

Install Multiple Version of Tensorflow Into Python Virtual Environment

You can use multiple version of tensorflow by creating python virtual environment.
"venv" module of python is used to create and manage virtual environments.


How to create python virtual environment:

  • Install the python3-venv module
sudo apt-get update 
sudo apt-get install python3-venv
  • Go to the directory, where you want to create virtual environment.
  • Type following code to create virtual environment
python3 -m venv environment_name
  • Activate the virtual environment
source environment_name/bin/activate


Congratulations!!! You have created and activated your virtual environments.


Installing Tensorflow into virtual environment:

  • Upgrade your pip command using following code
pip install --upgrade pip
  • Install specific version of tensorflow you want
pip install tensorflow==1.13.1

Check, if tensorflow is successfully installed or not:

  • Create a file named "welcome.py"
gedit welcome.py
  • Write the following code into it and save it.
import tensorflow as tf
welcome = tf.constant('Welcome to python virtual environment!')
sess = tf.Session()
print(sess.run(welcome))
  • Run the file
python welcome.py

If it shows the output "Welcome to python virtual environment!", then tensorflow is installed successfully.

Congratulations!!! You have successfully installed tensorflow into virtual environment!

Running code:

To run code create python file with '.py' extension and run it from the virtual environment with the python following the 'program_name.py'.

Almost finished today!
If you feel any problem, please let me know.
Happy Learning!



Install Multiple Version of Tensorflow Into Python Virtual Environment Install Multiple Version of Tensorflow Into Python Virtual Environment Reviewed by Ikram on 7/11/2020 09:17:00 PM Rating: 5

No comments:

Powered by Blogger.