[英]Pylint doesn't recognize my Python imports on VS Code, but the code runs without any error
I'm working on Windows 7 64bits with Anaconda 3. On my environment Nifti, I have installed Tensorflow 2.1.0, Keras 2.3.1 and Python 3.7.7.
在 Visual Studio Code 上,所有这些导入都存在问题:
from tensorflow.python.keras.models import Model
from tensorflow.keras.layers import Input, Dense, Conv2D, Conv2DTranspose, UpSampling2D, MaxPooling2D, Flatten, ZeroPadding2D
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import Adam
我收到这些错误:
No name 'python' in module 'tensorflow'
Unable to import 'tensorflow.python.keras.models'
Unable to import 'tensorflow.keras.layers'
Unable to import 'tensorflow.keras.preprocessing.image'
Unable to import 'tensorflow.keras.optimizers'
Visual Studio Code 使用相同的 anaconda 环境: D:\Users\VansFannel\Programs\anaconda3\envs\nifti
。 我在 Visual Studio 中的“Python:Select 解释器命令”选项上检查了它。
If I do this on a CMD shell with nifti environment activate, python -c 'from tensorflow.python.keras.models import Model
, I don't get any error.
如果我使用iPython :
from tensorflow.python.keras.models import Model
我也没有收到任何错误。
我检查了python.pythonpath
设置,它指向: D:\Users\VansFannel\Programs\anaconda3\envs\nifti
在左下角我可以看到:
当我在 Visual Studio Code 上打开一个新终端时,我收到以下消息:
Microsoft Windows [Versión 6.1.7601] Copyright (c) 2009 Microsoft Corporation. Reservados todos los derechos. D:\Sources\Repos\University\TFM\PruebasPython\Nifty>D:/Usuarios/VansFannel/Programs/anaconda3/Scripts/activate (base) D:\Sources\Repos\University\TFM\PruebasPython\Nifty>conda activate nifti (nifti) D:\Sources\Repos\University\TFM\PruebasPython\Nifty>
如果我使用Ctrl. + F5
Ctrl. + F5
,尽管它在“ Problems
”选项卡上显示错误,但它运行时没有任何错误。
使用 pyCharm,我没有收到任何错误。
我如何解决这个问题?
如果您使用的是 Anaconda 虚拟环境
示例:
E:/Softwares/AnacondaFolder/Scripts/activate
这现在应该显示(基础)写在文件夹路径的开头
示例:
conda activate Nifti
现在应该显示(Nifti)写在文件夹路径的开头
现在,如果你导入了一些东西,VS Code 会识别它。
我试过你的代码,我的建议是从 pylint 切换到其他 lintings。 远离那种愚蠢的棉绒。 也许你可以试试 flake8: "python.linting.pylintEnabled": false, "python.linting.flake8Enabled": true,
出现这个问题是因为pylint无法搜索到Anaconda的路径,因为'tensorflow'只能通过conda安装,只能选择Anaconda创建的环境。 但是pylint不能跟随环境的变化去改变搜索路径,所以会提示import error。 愚蠢的棉绒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.