I had the same problem with Windows 10 x64, and it was caused because I was using the wrong Python version, both globally and in the venv
. I found questions on the issue multiple times on the internet, including yours.
Be sure to use Python versions 3.5-3.8, as per requirements, but also x64, not x32.
Namely, I ran into this error using both
- a
venv
with 3.9.1 x64
(python --version
),
- and my globally installed
3.8.2 x32
(python3 --version
).
So, I downloaded the x64-version of Python 3.8.6 from here.
Note that the command venv
does not allow specifying the python version used in the virtual environment,
as per an answer on this question. So I used virtualenv
, which I obviously had to install in my global Python version first.
To specify the Python version used in the venv
, I used the command virtualenv
, as in:
virtualenv --python="C:\Users\me\AppData\Local\Programs\Python\Python38\python.exe myvenv
where you have to give the path to the newly downloaded Python distribution you want to use, if there are several on your PC (for example, I had Python38-32
and Python39
folders in that directory).
Check Python versions in virtual environment
After I activate my myvenv
, created as above, I verify the Python versions as follows:
python3 --version
> Python 3.8.2
python --version
> Python 3.8.6
Then, using the command
import struct
print(struct.calcsize("P") * 8)
Within either python3
or python
, shows me whether the version is 32bit or 64bit, as per this answer. The python
returns a 64
, so that is the one you want to use (not python3
).
Finally, within the virtual environment, you can run
pip install --upgrade tensorflow
and it will download and install. (Meanwhile, pip3 install --upgrade tensorflow
would still return your error inside and outside the virtual enviroment.)