Correct way to install tensorflow v1 in virtual environment

I created a virtual environment and installed intel-tensorflow package but while importing tensorflow I get following error:

>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'

Steps that I tried are below:

user@clearos~/.virtualenvs $ python -m venv my_env
user@clearos~/.virtualenvs $ source my_env/bin/activate
(my_env) user@clearos~/.virtualenvs $ pip --no-cache-dir install intel-tensorflow
Collecting intel-tensorflow
Downloading https://files.pythonhosted.org/packages/6b/62/b63a6b446ffe15a63a63c2d1f2ae7d19666e7276df07835a3898737c2ff2/intel_tensorflow-0.0.1-py2.py3-none-any.whl
Requirement already satisfied: pip>=10.0.1 in ./my_env/lib/python3.8/site-packages (from intel-tensorflow) (19.2.3)
Installing collected packages: intel-tensorflow
Successfully installed intel-tensorflow-0.0.1
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(my_env) user@clearos~/.virtualenvs $ python
Python 3.8.1 (default, Mar 30 2020, 14:50:54)
[GCC 9.3.1 20200327 releases/gcc-9.3.0-58-g070a0b6392] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'

I downgraded pip to version 19.0 as mentioned in https://software.intel.com/en-us/articles/intel-optimization-for-tensorflow-installation-guide#inpage-nav-1-4 and tried again installing the tensorflow. Got the same module not found error.

(my_env) user@clearos~/.virtualenvs $ pip install intel-tensorflow
Collecting intel-tensorflow
  Using cached https://files.pythonhosted.org/packages/6b/62/b63a6b446ffe15a63a63c2d1f2ae7d19666e7276df07835a3898737c2ff2/intel_tensorflow-0.0.1-py2.py3-none-any.whl
Requirement already satisfied: pip>=10.0.1 in ./my_env/lib/python3.8/site-packages (from intel-tensorflow) (19.0)
Installing collected packages: intel-tensorflow
Successfully installed intel-tensorflow-0.0.1
You are using pip version 19.0, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

(my_env) user@clearos~/.virtualenvs $ python
Python 3.8.1 (default, Mar 30 2020, 14:50:54) 
[GCC 9.3.1 20200327 releases/gcc-9.3.0-58-g070a0b6392] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'tensorflow'

I tried using --no-cache-dir option with pip install but got another error.

(my_env) user@clearos~/.virtualenvs $ pip --no-cache-dir install intel-tensorflow
Collecting intel-tensorflow
  Downloading https://files.pythonhosted.org/packages/6b/62/b63a6b446ffe15a63a63c2d1f2ae7d19666e7276df07835a3898737c2ff2/intel_tensorflow-0.0.1-py2.py3-none-any.whl
Requirement already satisfied: pip>=10.0.1 in ./my_env/lib/python3.8/site-packages (from intel-tensorflow) (19.0)
Exception:
Traceback (most recent call last):
  File "/home/user/.virtualenvs/my_env/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 176, in main
    status = self.run(options, args)
  File "/home/user/.virtualenvs/my_env/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 344, in run
    build_failures = wb.build(
  File "/home/user/.virtualenvs/my_env/lib/python3.8/site-packages/pip/_internal/wheel.py", line 848, in build
    assert building_is_possible
AssertionError

Can anybody please provide a solution ?

Have you installed tensorflow in you virtual environment?

yeah, thats what I’m trying to install using pip. Buts its not working.

What I see in your log message is that you installed intel-tensorflow, not tensorflow.

While installing normal tensorflow v1 , I get following error

(my_env) user@clearos~/.virtualenvs $ pip install tensorflow-cpu==1.15
Collecting tensorflow-cpu==1.15
  Could not find a version that satisfies the requirement tensorflow-cpu==1.15 (from versions: 2.2.0rc1, 2.2.0rc2)
No matching distribution found for tensorflow-cpu==1.15
You are using pip version 19.0, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

The non-gpu tensorflow is called ‘tensorflow’ not ‘tensorflow-cpu’

I tried with both, tensorflow and tensorflow-cpu. No success in either. Same error message.

(my_env) user@clearos~/.virtualenvs $ pip install tensorflow==1.15
Collecting tensorflow==1.15
  Could not find a version that satisfies the requirement tensorflow==1.15 (from versions: 2.2.0rc1, 2.2.0rc2)
No matching distribution found for tensorflow==1.15

Your python version needs to be 3.5-3.7.

https://www.tensorflow.org/install/pip

Ohh… missed the requirement. Thanks for pointing out.
Is there a way to install python3.7 in clear linux as I could not find any specific bundle for that. Also based on this thread https://community.clearlinux.org/t/best-way-to-install-a-specific-version-of-python-in-the-clearlinux-docker-container/2056 it appears that I can not downgrade python in clear linux. Any thoughts on how can I install python 3.7 ?

Install Pyenv (by yourself)

@doct0rHu thanks for pointing towards pyenv. Really useful.
Also pyenv-virtualenv plugin lets you manage virtualenv fair simply.