New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'MSVCCompiler' object has no attribute '_MSVCCompiler__version' #69437
Comments
Hi distutils. I wrote a setup.py that conditions on compiler type, following the guide at [1]. I needed to add an extra include when the compiler is an msvc version older than 9.0 (infamously missing stdint.h [2]) Anyway the code I wrote to do this was: if self.compiler.compiler_type == "msvc" and int(self.compiler._MSVCCompiler__version) <= 9: Which worked fine on all Python versions (tested 2.7 through 3.4) UNTIL the recent release of Python 3.5. On Python 3.5 I get the error: AttributeError: 'MSVCCompiler' object has no attribute '_MSVCCompiler__version' Oh no. My fault I suppose for relying on a private variable. Can you suggest a more reliable way to test "compiler is msvc <= 9.0"? The test should be compatible all Python versions 2.7 through 3.5 so it can safely go in a setup.py Can you help? [1] http://stackoverflow.com/a/5192738/284795 |
if sys.version_info[:2] >= (3, 3):
# MSVC version is >= 9.0 Alternatively: if sys.version_info[:2] >= (3, 5):
# MSVC version is >= 14.0, or
# _msvccompiler.MSVCCompiler does not have __version or if self.compiler.compiler_type == "msvc" and int(getattr(self.compiler, '_MSVCCompiler__version'), 10) <= 9: |
Hi Steve. Thanks for your reply. In the end I went with your something On 29 September 2015 at 05:27, Steve Dower <report@bugs.python.org> wrote:
|
Well __version is determined by looking at sys.version to see what version was used to build Python, so you aren't really getting the "actual" one, though in practice it doesn't matter. For Python 3.5 and later you could get different versions from the one that was used to build, but it will always be at least 14.0 and there's deliberately no way for people to depend on that information other than in C source code. |
It matters if you're trying to write a library that builds reliably
...for all Python versions 2.6 through 3.5 (24 combinations!) Anyway I Yes I saw that blog post—your blog post—about compiler independence [2] [1] http://stackoverflow.com/q/3297254/284795 On 29 September 2015 at 14:05, Steve Dower <report@bugs.python.org> wrote:
|
Once you've established that MSVC is being used, you can infer the version from the Python version, is what I meant by "it doesn't matter". The version attribute on the compiler instance is never going to differ pre-3.5, and post-3.5 it doesn't even exist. Generally, I'd say you're safer to detect and check _MSC_VER in your C code if it's relevant, as that will also handle builds that don't go via your setup.py. |
Yes you're right. My setup.py if you're curious Separately, I think compiler=mingw32 is broken in Python 3.5 on computers On 29 September 2015 at 16:24, Steve Dower <report@bugs.python.org> wrote:
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: