Skip to content
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

mypy can't find typeshed directory when installed using pyenv python/pip #3211

Closed
mdeland opened this issue Apr 21, 2017 · 9 comments
Closed

Comments

@mdeland
Copy link

mdeland commented Apr 21, 2017

mypy can't find typeshed directory when installed via a pyenv'd python version.

On OSX.
python version 3.5.2, installed with pyenv

$ which python
>> ~/.pyenv/shims/python
$ pip install mypy
$ pip show mypy
>> Name: mypy
>> Version: 0.501
>> ...
>> Location: ~/.pyenv/versions/3.5.2/Python.framework/Versions/3.5/lib/python3.5/site-packages
$ which mypy
>> ~/.pyenv/shims/mypy
$ mypy test.py
>> test.py: error: Name '__builtins__' is not defined
>> test.py:1: error: Name 'int' is not defined
>> test.py:1: error: Cannot find module named 'builtins'
>> test.py:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
>> test.py:1: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues
>> test.py:1: note: please use --show-traceback to print a traceback when reporting a bug

compare to:

mypy test.py  --custom-typeshed-dir ~/.pyenv/versions/3.5.2/Python.framework/Versions/3.5/lib/mypy/typeshed/

which works fine.

@gvanrossum
Copy link
Member

You're going to have to debug this yourself, I'm not familiar with pyenv.

@mdeland
Copy link
Author

mdeland commented Apr 21, 2017

Happy to close this, but I brought up the problem in the gitter room and @JelleZijlstra suggested it should be opened as an issue.

@gvanrossum
Copy link
Member

Sorry, it's fine as an issue, and if you come up with a fix we'll happily review a PR if you send it, I just don't think the core team can fix it without your help (since it's a config issue and it's happening on your computer).

@mdeland
Copy link
Author

mdeland commented Apr 21, 2017

Got it, will do.

@ghost
Copy link

ghost commented Apr 28, 2017

@grafi-tt
Copy link
Contributor

I have the same problem, but the cause is different from both of @mdeland and @Socialery 's.

On Gentoo Linux, user-installed Python locates site-packages on the directory named lib64.

For example, in my Linux environment, mypy library is located on ~/.local/lib64/python3.6/site-packages/mypy. So simply checking lib64 fixes the issue. Just to make sure, the patch also checks lib32.

I'm not tried, but I believe the same problems occurs even if I installed Python and mypy globally, by manual build or packagemanager. On Gentoo /usr/bin/lib is the symbolic link of /usr/bin/lib64. Therefore __file__ becomes something like /usr/lib64/python3.6/site-packages/mypy/build.py.

--- mypy/build.py.old	2017-07-22 16:24:01.127723181 +0900
+++ mypy/build.py	2017-07-22 16:25:20.252575559 +0900
@@ -224,8 +224,8 @@
             lib = parent
             for i in range(2):
                 lib = os.path.dirname(lib)
-                if os.path.basename(lib) == 'lib':
-                    return os.path.join(lib, 'mypy')
+                if os.path.basename(lib) in ('lib', 'lib32', 'lib64'):
+                    return os.path.join(os.path.dirname(lib), 'lib/mypy')
         subdir = os.path.join(parent, 'lib', 'mypy')
         if os.path.isdir(subdir):
             # If installed via buildout, the __file__ is

The cause of @mdeland's report seems to be non-standard bin directory created by pyenv. I think #3074 resolved this problem. Though I'm not familiar with Windows, as I looked @Socialery's report, the problem is about the directory structure of installed Python.

@gvanrossum
Copy link
Member

gvanrossum commented Jul 22, 2017 via email

@gvanrossum
Copy link
Member

Is this still an issue with mypy 0.550?

@mdeland
Copy link
Author

mdeland commented Dec 5, 2017

fixed for me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants