0

I have a functioning program on a Jupyter notebook. I downloaded it as a .py file but, for some reason, I get errors while making the imports that, in jupyter, didn't cause any problems. The imports are:

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import *
from tensorflow.keras.callbacks import ModelCheckpoint 
from tensorflow.keras.losses import MeanSquaredError
from tensorflow.keras.metrics import RootMeanSquaredError 
from tensorflow.keras.optimizers import Adam

and I get the errors:

Import "tensorflow.keras.<name>" could not be resolved

It's so weird since the only difference is the file itself (from .ipynb to .py), it's the same environment and even the same folder.

I have tensorflow version: 2.8.0 And python version: 3.10.4

walter
  • 193
  • 9
  • I think the conversion in .py file didn't work. I think in the code you have a lot of garbage (like tensorflow.keras.) for same reason. Did you use the built option of Jupyter to download the .py file (https://stackoverflow.com/questions/54647056/how-to-download-a-py-file-from-jupyter-lab-notebook)? – SimoX Apr 28 '22 at 18:30
  • @SimoX I did use the built option. I'm not entirely sure what you mean by "garbage", I imported what I needed. – walter Apr 28 '22 at 18:48
  • I understand, so try to eliminate this row tensorflow.keras.layers import *, and import only the used layers. In general it is not recommended to use *, maybe python tries to import something that doesn't exist (like tensorflow.keras.). – SimoX Apr 28 '22 at 19:17
  • 1
    How is this question different from [your earlier one](https://stackoverflow.com/q/72043656/8508004)? What makes you think it is the same environment? Both questions would be explained by that not being the case. – Wayne Apr 28 '22 at 19:26
  • @Wayne what do you mean "What makes you think it is the same environment?"?. I specify the environment myself. – walter Apr 28 '22 at 19:32
  • You've checked the environment from inside the notebook? The information is the same as if you ran the commands checking the versions and such where you run the script version? – Wayne Apr 28 '22 at 19:57

0 Answers0