I am completely new to Python and am learning concepts through a course. In the course we are required to import tensorflow so I installed the package on my computer, however, when I attempt to import, I am getting an error.
Here is what I have written for the code:
import numpy as np
import tensorflow as tf
Here is the error:
Traceback (most recent call last):
File “C:\Users\PLV3272\PycharmProjects\PythonProject5\IN501_Martinez_Unit8_Assignment.py”, line 2, in
import tensorflow as tf
File “C:\Users\PLV3272\AppData\Roaming\Python\Python312\site-packages\tensorflow_init_.py”, line 30, in
import distutils as _distutils
ModuleNotFoundError: No module named ‘distutils’
Is anyone able to help me troubleshoot? I read that distutils is not available with Python 3.12, which is what I am using. One solution I read said to install setuptools, however, I show a few different setuptools options within the packages (setuptools-scm, setuptools-git, setuptools-rust), I am also utilzing my work computer so I am not sure if that is somehow contributing tot he issues. I have successfully installed other packages (numpy, pandas).
Code and tracebacks are more readable if you quote them like it recommends here: About the Python Help category (Notice how it has garbled __init__?)
I can confirm that’s normal:
Python 3.12.1
PS vsj> python -c "import distutils"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'distutils'
If the version of tensorflow you have is compatible with 3.12, it shouldn’t require something not in 3.12 (or it should force it to be installed). So I wonder if you have pinned the version of TF to an old one, or otherwise managed to get one from an earlier Python? Reinstall the latest?