from tensorflow.keras.layers import Dense,Flatten,Input
打印一下路径:
import tensorflow as tf
import keras
print(tf.__path__)
print(keras.__path__)
['E:\\开发工具\\pythonProject\\studyLL\\venv\\lib\\site-packages\\keras\\api\\_v2',
'E:\\开发工具\\pythonProject\\studyLL\\venv\\lib\\site-packages\\keras\\_tf_keras',
'E:\\开发工具\\pythonProject\\studyLL\\venv\\lib\\site-packages\\tensorflow_estimator\\python\\estimator\\api\\_v2',
'E:\\开发工具\\pythonProject\\studyLL\\venv\\lib\\site-packages\\tensorboard\\summary\\_tf', 'E:\\开发工具\\pythonProject\\studyLL\\venv\\lib\\site-packages\\tensorflow',
'E:\\开发工具\\pythonProject\\studyLL\\venv\\lib\\site-packages\\tensorflow\\_api\\v2']
['E:\\开发工具\\pythonProject\\studyLL\\venv\\lib\\site-packages\\keras']
做一下修改,分开来引用:
import tensorflow as tf import keras from keras.layers import Dense,Flatten,Input from keras.models import Model from tensorflow.python.keras.layers.embeddings import Embedding from keras.preprocessing.sequence import pad_sequences from keras.preprocessing.text import one_hot import numpy as np
运行报错:
ImportError: Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires
that these DLLs be installed in a directory that is named in your %PATH% environment variable.
You may install these DLLs by downloading "Microsoft C++ Redistributable for Visual
Studio 2015, 2017 and 2019" for your platform from this URL:
https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads
链接:https://learn.microsoft.com/zh-CN/cpp/windows/latest-supported-vc-redist?view=msvc-170
下载x64进行安装
再次运行tensorflow就ok了。