I am using the pythonnet
package in MSMQ communications. In my IDE (PyCharm CE), I have the following sample code:
#!/usr/bin/env python3
import pythoncom
import clr
clr.AddReference("System")
clr.AddReference("System.Messaging")
from System import TimeSpan
from System.Messaging import MessageQueue
Aside: this code works fine when I actually run it using Python 3.6
.
And below is a screenshot of what it looks like inside PyCharm.
System
it says: Unresolved reference 'System'
Other than using noqa
comments, how can I get my PyCharm linting to do the following:
from System import XYZ
?Versioning Info
2019.2
2.3.0
, installed in a virtual environmentThis is my complete answer, according to our exchanges.
No module named clr
After some checks, it seems there was a kind of mix between the operating system environment, and your project's virtual environment.
Solution: delete and re-create properly virtual environment fixed it
Unresolved reference 'System'
In this case where corresponding modules are loaded dynamically, your best solution is to disable PyCharm's Inspector on these specific lines; thus you won't loose anything else in your IDE.
You can see How to disable inspection.
In my sandbox, I just had to:
More actions
context menu on the error (System
in this case)Ignore unresolved reference 'pythonnet_tests.System'
sub-menuSuppress for statement
Each time the corresponding source code line, will be preceded by a comment line:
# noinspection PyUnresolvedReferences
And that's it!