-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
When using virtualenv, mypy has to be installed in virtualenv before project is installed #7237
Comments
Actually, I need to amend this after a lot more experimentation. I need to replace scenario 2 above (install project dependencies and THEN MyPy) with the following:
Note that the only thing I'm changing between each scenario is the virtualenv. I'm not refreshing the project clone or clearing cache directories. But, importantly, I can move from a failing scenario to a successful scenario without deleting any cache directories, so I believe this rules out any local (in the project directory) cache directories being the culprit. |
@ethanhs Do you have time to look at this issue? It seems related to PEP 561 support. |
Sure, I can take a look at it a bit later. |
I'm afraid I am unable to reproduce this, though perhaps this is an issue with mkvirtualenv (I am not familiar with how it works). Here is what I tried:
Do you have a sequence of commands I could run to reproduce this? |
You got it backwards. The problem isn't seen in Conformity. It's seen in projects that use Conformity. These exact steps should replicate the problem for you. Includes steps that don't work, steps that do work, and a conclusion. Create a new project directory with these three files:
from setuptools import setup
setup(
name='test_typing',
version='1.0.0',
description='Python library to test typing',
author='Nick Williams',
packages=[
str('test_typing'),
],
install_requires=['conformity~=1.25'],
license='Apache 2.0',
)
from conformity import fields
field: fields.Base = fields.Dictionary({}, allow_extra_keys=True) Prerequisite
Steps that Don't Work
Steps that Do Work
Conclusion Note |
So I think I found the issue. It appears mypy is discovering the system Python installation because we try to execute Try For now you can add |
I don't think that's it. As you'll see in the Steps that Do Work section in my previous comment, it does work in a virtualenv as long as you install
) |
Ok, coming back to this with a fresh set of eyes, the issue is that the global mypy is conflicting with the virtualenv mypy. (i.e. when you run I am going to close this, but I filed #17214 to make it clearer when this issue happens. |
Following this issue as well. I have mypy plugin installed in pycharm and when creating a project with it (standard flow: New Project -> Interpreter type: project venv) importing any library in that project will result in mypy reporting that the library can't be found. @ethanhs would this cover the reported as well or should i open a new issue? |
I'm afraid I'm unfamiliar with how PyCharm venv management works. Is your mypy installed in the same venv as the project or globally? |
It's not a feature request. I'm pretty sure it's a bug, but it might be a bug in the form of incomplete documentation (i.e., this is an undocumented feature), or it might be part code bug part documentation bug.
Please see the open source project https://github.com/eventbrite/conformity. It has a
py.typed
file and MyPy does successfully use that in other projects, but only in certain circumstances.mypy
already installed in the system Python 3.7.mkvirtualenv
for a new project with Conformity in its dependencies and using Conformity types.pip install mypy
in the virtualenv, then install the project dependencies.mypy .
in the project works without any errors.mypy
already installed in the system Python 3.7.mkvirtualenv
for the same project. Install the project dependencies, thenpip install mypy
in the virtualenv, too.mypy .
in the project results in import errors about Conformity.mypy
already installed in the system Python 3.7.mkvirtualenv
for the same project. Install the project dependencies but do not installmypy
in the virtualenv.mypy .
in the project results in import errors about Conformity.mypy
before or after you install the project dependencies (namely Conformity). It appears that, in this scenario, MyPy is using the system Python path instead of the virtualenv Python path, even thoughwhich mypy
is correct (see below).mypy
command shebang vs. the virtualenvpython
). However, this isn't documented anywhere, so it should be.I have not tried installing Git from master because the problem is not version-dependent AFAICT. It is install-order dependent. I did, however, look for any other similar issues that had been addressed, or documentation that could help here, and found none.
No crash.
The text was updated successfully, but these errors were encountered: