-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Python executable inference not run when using --py2 of --python-version #8504
Comments
https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-python-version
@mikolajz but you'd usually want to point mypy at your python 2.7 virtual environment with https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-python-executable |
What we have in our case is a Docker image where the system Python2 is configured the way we like. It worked, but it was surprising why it didn't find the system libraries, instead trying to use Python3 system libraries. It would be especially nice if it worked out of the box, since I couldn't find any hints of what libraries directory is used in any debug output, so have to add ad hoc debug prints to mypy source code to understand what's happening. |
@mikolajz if you point to the Python 2 executable it will be searched. Finding a Python executable is not an easy problem to solve in the general case, and choosing the wrong one is problematic. If you want to see what libraries are used, I believe -vv will indicate this information |
Right, -vv gives lots of useful info, including the paths that are used - thanks for the hint (maybe I was using only one I personally don't care that much about a solution, since I already know that I need to add --python_executable, but it's quite tricky (and, as @graingert pointed, contrary to the flag documentation which promises that the proper binary will be searched). Maybe you should print a warning if someone tries to use --python-version without --python-executable? Is there a valid usecase for this? |
Closing due to Python 2 feature freeze (#12237). |
Are you reporting a bug, or opening a feature request?
I would say a bug.
What is the actual behavior/output?
When using the --py2 flag, one needs to additionally pass --python-executable=/usr/bin/python2 flag for mypy to find site packages.
What is the behavior/output you expect?
mypy should find the Python 2 binary on its own. I think it's a bug since there is code in main.py to do it, but it's run only when
options.python_executable
is None (c.f.infer_python_version
). However,Options.__init__
initializes it with sys.executable and it's not None.Changing
Options.__init__
to initialize it to None fixes the problem, but I don't know if it may have negative side-effects.I think the same applies to using --python-version to set any version different than the one mypy runs on.
What are the versions of mypy and Python you are using?
mypy 0.761 running undef Python 3.5.2 to analyze Python 2.7.12 code.
Do you see the same issue after installing mypy from Git master?
Not checked, but the relevant code all looks the same.
The text was updated successfully, but these errors were encountered: