0

I'm trying to install tensorflow with pip in virtualenv in Anaconda for Windows 10. After activating my virtualenv, when I run pip install tensorflow, I get an error:

ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow

This might be because tensorflow doesn't support Python3.8 which I am using. The update of the post says that it should now work, but it doesn't for me. I tried what the answers suggest with no better luck.

So, I tried the following to downgrade to Python3.7:

But any of these attempts incredibly see Python switch back to version 3.8 when I activate the virtualenv. Even if I destroy the environment and create it again in the older Anaconda.

I also tried py -3.7 -m pip install tensorflow in the Anaconda with Python3.7 (it doesn't find the correct version of Python when using the more recent Anaconda). It lead to the error:

Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

I fixed it running conda update wrapt and launched the tensorflow installation command again. After many package installations and removals, it displayed the following error:

ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.

We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.

pytest-doctestplus 0.2.0 requires pytest>=2.8.0, but you'll have pytest 0.0.0 which is incompatible. pytest-astropy 0.5.0 requires pytest>=3.1.0, but you'll have pytest 0.0.0 which is incompatible.

And in effect, I can see that the installation didn't work:

  • pip freeze > requirements.txt creates an empty requirements.txt

  • in the Python console, when I try to import keras, it resolves to:

     Traceback (most recent call last):
       File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 3, in <module>
         from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
     ModuleNotFoundError: No module named 'tensorflow'
    
     During handling of the above exception, another exception occurred:
    
     Traceback (most recent call last):
       File "<stdin>", line 1, in <module>
       File "C:\Users\my_private_path\venv\lib\site-packages\keras\__init__.py", line 5, in <module>
         raise ImportError(
     ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
    

It seems that no matter how many paths I try, tensorflow doesn't like virtualenv in Anaconda. Would someone have a path that works?

Codoscope
  • 692
  • 6
  • 14

1 Answers1

1

I use virtual environments with tensorflow all the time and it works fine. First use Anaconda to create a new environment. From the Anaconda home page click on Environments. When the Environment page appears click on create. A new window will pop up. Give the environment a name (for example call it tf), check the python checkbox. From the dropdown select python 3.7. A new environment called tf is created with python 3.7 installed. Now go to the Anaconda prompt which is conda. type in conda activate tf. Now use conda to install tensorflow (do not use pip). Conda automatically installs cudnn 7.6.5 and CUDA Toolkit 10.1.243 and tensorflow 2.1.0. If you want tensorflow 2.2 first install 2.1.0 as described. Then use pip to install 2.2 with pip install tensorflow ==2.2.0. 2.2 is compatible with the toolkit and cudnn versions installed with 2.1. Conda can only install tensorflow up to version 2.1.0. Install whatever other packages you need using either pip or conda.

Gerry P
  • 4,258
  • 2
  • 5
  • 15
  • It worked. For future visitors, here are the steps I followed: `conda create --name py371 python=3.7.1 --channel conda-forge` `conda activate py371` `conda install tensorflow` `virtualenv venv` `venv\Scripts\activate` `pip install tensorflow==2.2.0`. – Codoscope Oct 05 '20 at 16:46
  • glad it solved your problem. They should modify the pip installation so it works like the conda installation. Hope the folks at Anaconda upgrade it for higher versions soon – Gerry P Oct 07 '20 at 16:00
  • It would be great because I figured a downside with this technique: `pip freeze`ing creates absolute paths and `pip install`ing doesn't work. Running `pip install tensorflow==2.2.0` every time is necessary. – Codoscope Oct 07 '20 at 17:37