在Visual Studio 2017中运行pylint不起作用

时间:2018-02-15 08:52:49

标签: python-3.x visual-studio pylint

我在我的虚拟环境中安装了pylint,并在解决方案中配置并激活了虚拟环境。

当我通过命令提示符运行pylint时(激活虚拟环境之后),它可以工作:

C:\Users\AmosH\Documents\Workspace\local_gallery>pylint projects
Using config file C:\Users\AmosH\Documents\Workspace\local_gallery\.pylintrc
************* Module projects.admin
C:  1, 0: Missing module docstring (missing-docstring)
************* Module projects.apps
C:  1, 0: Missing module docstring (missing-docstring)
C:  4, 0: Missing class docstring (missing-docstring)
************* Module projects.models
C:  1, 0: Missing module docstring (missing-docstring)
C:  5, 0: Missing class docstring (missing-docstring)
C: 15, 4: Missing method docstring (missing-docstring)
...

-----------------------------------
Your code has been rated at 2.29/10

但是当我在Visual Studio中运行它时(右键单击项目> Python>运行PyLint)它只会显示奇怪的警告:

Severity    Code    Description Project File    Line    Suppression State
Warning     No module named general\admin.py [F:fatal]  local_gallery   general\admin.py    1   
Warning     No module named download_some_images.py [F:fatal]   local_gallery   download_some_images.py 1   
Warning     No module named general\apps.py [F:fatal]   local_gallery   general\apps.py 1   
Warning     No module named general\management\commands\populate_db.py [F:fatal]    local_gallery   general\management\commands\populate_db.py  1   
Warning     No module named general\management\commands\__init__.py [F:fatal]   local_gallery   general\management\commands\__init__.py 1   
Warning     No module named general\management\__init__.py [F:fatal]    local_gallery   general\management\__init__.py  1   
Warning     No module named general\migrations\__init__.py [F:fatal]    local_gallery   general\migrations\__init__.py  1   
Warning     No module named general\models.py [F:fatal] local_gallery   general\models.py   1   
Warning     No module named general\templatetags\lg.py [F:fatal]    local_gallery   general\templatetags\lg.py  1   
Warning     No module named general\tests.py [F:fatal]  local_gallery   general\tests.py    1   
Warning     No module named general\views.py [F:fatal]  local_gallery   general\views.py    1   
Warning     No module named general\__init__.py [F:fatal]   local_gallery   general\__init__.py 1   
Warning     No module named local_gallery\renderers.py [F:fatal]    local_gallery   local_gallery\renderers.py  1   
Warning     No module named local_gallery\settings.py [F:fatal] local_gallery   local_gallery\settings.py   1   
Warning     No module named local_gallery\urls.py [F:fatal] local_gallery   local_gallery\urls.py   1   
...

每个文件都无法加载自身,或类似的东西(请注意,每个模块都不会尝试加载其他模块,但本身并且失败)。

当我双击任何警告时,我可能会收到如下错误:

enter image description here

或另一个引用我" C:\ Users \ AmosH \ AppData \ Roaming \ Microsoft \ VisualStudio \ 15.0_e34de02d \ ActivityLog.xml",其中我会找到类似这样的内容:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\AmosH\Documents\Workspace\general\management\__init__.py'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at Microsoft.VisualStudio.Text.Implementation.TextDocumentFactoryService.OpenFileGuts(String filePath, DateTime& lastModifiedTimeUtc, Int64& fileSize) at Microsoft.VisualStudio.Text.Implementation.TextDocumentFactoryService.OpenFile(String filePath, DateTime& lastModifiedTimeUtc, Int64& fileSize) at Microsoft.VisualStudio.Text.Implementation.TextDocumentFactoryService.CreateAndLoadTextDocument(String filePath, IContentType contentType, Boolean attemptUtf8Detection, Boolean& characterSubstitutionsOccurred) at Microsoft.VisualStudio.Editor.Implementation.TextDocData.InitializeNewTextBufferFromFile(String fileName, Object source) at Microsoft.VisualStudio.Editor.Implementation.TextDocData.Load(String pszFilename, UInt32 grfMode, Int32 fReadOnly, Object source) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(Int32 hr, Int32[] expectedHRFailure) at Microsoft.VisualStudio.Shell.VsShellUtilities.OpenDocument(IServiceProvider provider, String fullPath, Guid logicalView, IVsUIHierarchy& hierarchy, UInt32& itemID, IVsWindowFrame& windowFrame, IVsTextView& view) at Microsoft.VisualStudioTools.Project.VsUtilities.OpenDocument(IServiceProvider serviceProvider, String filename, IVsTextView& viewAdapter, IVsWindowFrame& pWindowFrame) at Microsoft.VisualStudioTools.Project.VsUtilities.NavigateTo(IServiceProvider serviceProvider, String filename, Guid docViewGuidType, Int32 line, Int32 col) at Microsoft.PythonTools.Project.CustomCommand.ErrorListRedirector.OnNavigate(Object sender, EventArgs e) at Microsoft.VisualStudio.Shell.Task.OnNavigate(EventArgs e) at Microsoft.VisualStudio.Shell.Task.Microsoft.VisualStudio.Shell.Interop.IVsTaskItem.NavigateTo() at Microsoft.VisualStudio.ErrorListPkg.Shims.ErrorListPackageEventProcessor.PreprocessNavigate(ITableEntryHandle entryHandle, TableEntryNavigateEventArgs e) at Microsoft.VisualStudio.Shell.TableControl.Implementation.TableControlEventManager.<>c__DisplayClass40_0.<OnEntryElementNavigate>b__2(ITableControlEventProcessor p, ITableEntryHandle entry) at Microsoft.VisualStudio.Shell.TableControl.Implementation.TableControlEventManager.<>c__DisplayClass60_1`1.<EventProcessorHandler>b__0() at Microsoft.VisualStudio.Text.Utilities.GuardedOperations.CallExtensionPoint(Object errorSource, Action call) --- End of stack trace from previous location where exception was thrown --- at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

1 个答案:

答案 0 :(得分:0)

如果您没有选择.pyproj文件的位置作为项目的根目录,Visual Studio 2017中存在导致此问题的错误。在我的情况下,我选择了父目录,并且Visual Studio 2017没有对pylint在这些情况下工作所需的适当调整。每当我通过Visual Studio 2017运行pylint时,它都会在父目录中搜索模块,即使我可以使用Visual Studio 2017浏览我的项目并完全编辑文件。这确实很奇怪。