Skip to content

Editable install fails with ImportError (unknown location) on Windows 10 outside of venv #19089

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

Closed
wyattscarpenter opened this issue May 14, 2025 · 15 comments
Labels
bug mypy got something wrong topic-developer Issues relevant to mypy developers

Comments

@wyattscarpenter
Copy link
Contributor

wyattscarpenter commented May 14, 2025

Bug Report

python -m pip install -e ., which is recommended in CONTRIBUTING.md, does not work. The installation goes fine, but upon an attempted run, the installed mypy prints an error ending with:

checker.py", line 131, in <module>
    from mypy.plugins import dataclasses as dataclasses_plugin
ImportError: cannot import name 'dataclasses' from 'mypy.plugins' (unknown location)

Workaround

A non-editable install, python -m pip install ., works fine.

To Reproduce

python -m pip install -e . && mypy

Expected Behavior

mypy small help message, ie usage: mypy [-h] [-v] [-V] [more options; see below] etc

Actual Behavior

Crash with traceback, ending in

checker.py", line 131, in <module>
    from mypy.plugins import dataclasses as dataclasses_plugin
ImportError: cannot import name 'dataclasses' from 'mypy.plugins' (unknown location)

Your Environment

  • Mypy version used: master on git, mypy-1.16.0+dev.64b0a571e78c098316d69ebe280d8ea0d96a2737
  • Python version used: Python 3.12.8

Additional information

Previously, I'd always assumed my computer was just cursed in some way, and this was some idiosyncratic problem. But my google-fu was strong today and I discovered https://stackoverflow.com/questions/19602582/pip-install-editable-links-to-wrong-path, suggesting that there might be something wrong with setup.py.

Proposed test

It might be worth making a new basic test that tries installing with -e and performing some basic check.

@wyattscarpenter wyattscarpenter added the bug mypy got something wrong label May 14, 2025
@sterliakov sterliakov added the topic-developer Issues relevant to mypy developers label May 14, 2025
@sterliakov
Copy link
Collaborator

sterliakov commented May 14, 2025

Mhm, that's interesting, because I have no issues running editable installs (and that's in fact how I triage all issues - cd "$(mktemp -d)" && uv venv && uv pip install -e ~/Documents/Work/mypy && . .venv/bin/activate is my typical workflow). Could you add your environment info (os details, python installation manager, exact commands to reproduce) to the report?

$ cd "$(mktemp -d)" && uv venv && uv pip install -e ~/Documents/Work/mypy && . .venv/bin/activate
Using CPython 3.13.2
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
Resolved 4 packages in 1.08s
      Built mypy @ file:///home/stas/Documents/Work/mypy
Prepared 1 package in 1.09s
░░░░░░░░░░░░░░░░░░░░ [0/4] Installing wheels...                                                                                                                                                                   warning: Failed to hardlink files; falling back to full copy. This may lead to degraded performance.
         If the cache and target directories are on different filesystems, hardlinking may not be supported.
         If this is intentional, set `export UV_LINK_MODE=copy` or use `--link-mode=copy` to suppress this warning.
Installed 4 packages in 3ms
 + mypy==1.16.0+dev.920e8a52ba42229a8185c650491856de04948d32 (from file:///home/stas/Documents/Work/mypy)
 + mypy-extensions==1.1.0
 + pathspec==0.12.1
 + typing-extensions==4.13.2
$ mypy --version
mypy 1.16.0+dev.920e8a52ba42229a8185c650491856de04948d32 (compiled: no)

And same with plain pip, only 10 times slower:

$ cd "$(mktemp -d)" && python -m venv .venv && . .venv/bin/activate && pip install -e ~/Documents/Work/mypy
Obtaining file:///home/stas/Documents/Work/mypy
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Collecting typing_extensions>=4.6.0 (from mypy==1.16.0+dev.920e8a52ba42229a8185c650491856de04948d32)
  Using cached typing_extensions-4.13.2-py3-none-any.whl.metadata (3.0 kB)
Collecting mypy_extensions>=1.0.0 (from mypy==1.16.0+dev.920e8a52ba42229a8185c650491856de04948d32)
  Using cached mypy_extensions-1.1.0-py3-none-any.whl.metadata (1.1 kB)
Collecting pathspec>=0.9.0 (from mypy==1.16.0+dev.920e8a52ba42229a8185c650491856de04948d32)
  Using cached pathspec-0.12.1-py3-none-any.whl.metadata (21 kB)
Using cached mypy_extensions-1.1.0-py3-none-any.whl (5.0 kB)
Using cached pathspec-0.12.1-py3-none-any.whl (31 kB)
Using cached typing_extensions-4.13.2-py3-none-any.whl (45 kB)
Building wheels for collected packages: mypy
  Building editable for mypy (pyproject.toml) ... done
  Created wheel for mypy: filename=mypy-1.16.0+dev.920e8a52ba42229a8185c650491856de04948d32-0.editable-py3-none-any.whl size=8299 sha256=09214d624954892165b380b6daf5f6352a78dff2add32a3058fd796d163df2ca
  Stored in directory: /tmp/pip-ephem-wheel-cache-8lnpc815/wheels/5b/23/a9/84bf9b0754bf25dab9abd3a1233ab3d2bc254a038103794196
Successfully built mypy
Installing collected packages: typing_extensions, pathspec, mypy_extensions, mypy
Successfully installed mypy-1.16.0+dev.920e8a52ba42229a8185c650491856de04948d32 mypy_extensions-1.1.0 pathspec-0.12.1 typing_extensions-4.13.2
$ mypy
usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: Missing target module, package, files, or command.

I'm running a flavour of Ubuntu 24.04, with python installed with uv (3.13, first snippet) and system python (3.12.3 at /usr/bin/python, second snippet). Basic info:

$ uname -a; lsb_release -a
Linux pc 6.11.0-25-generic #25~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 15 17:20:50 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.2 LTS
Release:        24.04
Codename:       noble

@wyattscarpenter
Copy link
Contributor Author

wyattscarpenter commented May 14, 2025

Curious! Maybe my computer is cursed. I'll get more details on here in a while, but the most significant difference I detect is that I'm not using a venv. So maybe that lets mypy get confused about where things are.

Other edited-in details:

Python 3.12.8
mypy 1.16.0+dev.2ae3316e37ad1a9759d4fae0a9fd7199b5cfad74.dirty
pip 25.1.1 (python 3.12)
Latest Windows 10
Exact command to reproduce as above.

@emmatyping
Copy link
Member

One potential idea is that I believe the editable install mechanism may differ between platforms that support symlinks and those that don't.

@wyattscarpenter
Copy link
Contributor Author

wyattscarpenter commented May 15, 2025

On Windows cmd, which I'm using, the command is python -m venv .venv && ".venv/bin/activate.bat" && pip install -e ., and I get the same result.

Same if I cd up a directory, and then python -m venv .venv && ".venv/Scripts/activate" && pip install -e mypy (yes, it gave me a different activation script for some reason). —— I've realized these are useless because I didn't run python -m pip install -r test-requirements.txt first, but I did do that later and got the same result outside the venv (for both in the dir and from the parent dir).

Note to self: if I end up touching the project for this, edit the # For Windows use comment to say # For Windows use (powershell)


Interesting theory about the symlink! I do have symlinks turned on in Windows, btw. (If this does become relevant, one can see https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/ or https://portal.perforce.com/s/article/3472 for more information about that which I've forgotten in the years since I enabled symlinks for myself.)


on WSL, which I also have, testing on WSL1, meticulously following the instructions in CONTRIBUTING.md, it works.

Trying in windows cmd again, meticulously following the instructions in CONTRIBUTING.md, it works. However, just running python -m pip install -r test-requirements.txt && python -m pip install -e ., not in a venv, does not work.

It also works outside of a venv on wsl, although of course I have to use --break-system-packages

Trying pip install -e on windows on another package works.

When I say work/doesn't work here, I mean them all in the same way, from the OP. Here is the full traceback every time:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\[redcated]\AppData\Local\Programs\Python\Python312\Scripts\mypy.exe\__main__.py", line 4, in <module>
  File "C:\Users\[redacted]\mypy\mypy\__main__.py", line 9, in <module>
    from mypy.main import main, process_options
  File "C:\Users\[redacted]\mypy\mypy\main.py", line 16, in <module>
    from mypy import build, defaults, state, util
  File "C:\Users\[redacted]\mypy\mypy\build.py", line 42, in <module>
    import mypy.semanal_main
  File "C:\Users\[redacted]\mypy\mypy\semanal_main.py", line 37, in <module>
    from mypy.checker import FineGrainedDeferredNode
  File "C:\Users\[redacted]\mypy\mypy\checker.py", line 131, in <module>
    from mypy.plugins import dataclasses as dataclasses_plugin
ImportError: cannot import name 'dataclasses' from 'mypy.plugins' (unknown location)

@wyattscarpenter wyattscarpenter changed the title Editable install fails with ImportError (unknown location) Editable install fails with ImportError (unknown location) on Windows 10 outside of venv May 15, 2025
@A5rocks
Copy link
Collaborator

A5rocks commented May 15, 2025

I can't reproduce this in cmd.exe:

C:\Users\A5rocks\Documents\Temp\empty>python -m venv test-venv && "test-venv/Scripts/activate" && pip install -e ../../mypy && mypy x.py
Obtaining file:///C:/Users/A5rocks/Documents/mypy
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Collecting typing_extensions>=4.6.0 (from mypy==1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e)
  Using cached typing_extensions-4.13.2-py3-none-any.whl.metadata (3.0 kB)
Collecting mypy_extensions>=1.0.0 (from mypy==1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e)
  Using cached mypy_extensions-1.1.0-py3-none-any.whl.metadata (1.1 kB)
Collecting pathspec>=0.9.0 (from mypy==1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e)
  Using cached pathspec-0.12.1-py3-none-any.whl.metadata (21 kB)
Using cached mypy_extensions-1.1.0-py3-none-any.whl (5.0 kB)
Using cached pathspec-0.12.1-py3-none-any.whl (31 kB)
Using cached typing_extensions-4.13.2-py3-none-any.whl (45 kB)
Building wheels for collected packages: mypy
  Building editable for mypy (pyproject.toml) ... done
  Created wheel for mypy: filename=mypy-1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e-0.editable-py3-none-any.whl size=8327 sha256=59543fb2cc32a0113f10a892d43bf33393b3f541c500ae941975cb45bfc5c7a0
  Stored in directory: C:\Users\A5rocks\AppData\Local\Temp\pip-ephem-wheel-cache-5fjzjnb9\wheels\2d\33\52\8bfdf22373bb6491e803b67ef56f2e5c7f6fada4a0bac2f7fe
Successfully built mypy
Installing collected packages: typing_extensions, pathspec, mypy_extensions, mypy
Successfully installed mypy-1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e mypy_extensions-1.1.0 pathspec-0.12.1 typing_extensions-4.13.2

[notice] A new release of pip is available: 24.3.1 -> 25.1.1
[notice] To update, run: python.exe -m pip install --upgrade pip
Success: no issues found in 1 source file

@wyattscarpenter
Copy link
Contributor Author

@A5rocks what if you don't do it from inside a venv?

@sterliakov
Copy link
Collaborator

Works fine without venv in docker library/python:3.13 if I mount the repo and pip install -e it. So this is almost definitely windows-specific (TIL windows doesn't support symlinks, thanks @emmatyping!).

Unfortunately I won't be able to assist with debugging this problem further, sorry - too lazy to configure virtualbox and fight with windows licenses...

@emmatyping
Copy link
Member

Sure thing! I don't recall but symlinks may not be used even if enabled on Windows. @wyattscarpenter just confirming, you installed Python from official python.org installers?

@emmatyping
Copy link
Member

I also could not reproduce this FWIW.

@wyattscarpenter
Copy link
Contributor Author

Yep, that's where I got my Python from.

@A5rocks
Copy link
Collaborator

A5rocks commented May 17, 2025

@A5rocks what if you don't do it from inside a venv?

Sorry I forgot to do this, but I still can't reproduce this:

C:\Users\A5rocks\Documents\Temp\empty>py -3 -m pip install -e ../../mypy && mypy x.py
Obtaining file:///C:/Users/A5rocks/Documents/mypy
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Collecting typing_extensions>=4.6.0 (from mypy==1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e)
  Using cached typing_extensions-4.13.2-py3-none-any.whl.metadata (3.0 kB)
Collecting mypy_extensions>=1.0.0 (from mypy==1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e)
  Using cached mypy_extensions-1.1.0-py3-none-any.whl.metadata (1.1 kB)
Collecting pathspec>=0.9.0 (from mypy==1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e)
  Using cached pathspec-0.12.1-py3-none-any.whl.metadata (21 kB)
Using cached mypy_extensions-1.1.0-py3-none-any.whl (5.0 kB)
Using cached pathspec-0.12.1-py3-none-any.whl (31 kB)
Using cached typing_extensions-4.13.2-py3-none-any.whl (45 kB)
Building wheels for collected packages: mypy
  Building editable for mypy (pyproject.toml) ... done
  Created wheel for mypy: filename=mypy-1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e-0.editable-py3-none-any.whl size=8327 sha256=44aae54e329b6b48b1299513d4b43d1994ed8877d73b84ab2403c7bc75b23bae
  Stored in directory: C:\Users\A5rocks\AppData\Local\Temp\pip-ephem-wheel-cache-koiee2jn\wheels\2d\33\52\8bfdf22373bb6491e803b67ef56f2e5c7f6fada4a0bac2f7fe
Successfully built mypy
Installing collected packages: typing_extensions, pathspec, mypy_extensions, mypy
Successfully installed mypy-1.16.0+dev.501a07b45af8e44eda665e53526fc590dc5a014e mypy_extensions-1.1.0 pathspec-0.12.1 typing_extensions-4.13.2

[notice] A new release of pip is available: 24.3.1 -> 25.1.1
[notice] To update, run: python.exe -m pip install --upgrade pip
Success: no issues found in 1 source file

@wyattscarpenter
Copy link
Contributor Author

Dang, alright. I'm back to the hypothesis that my computer is cursed, I guess.

@wyattscarpenter
Copy link
Contributor Author

On a hunch, I tried downloading mypy to a new directory that doesn't have any spaces or punctuation in it. I got usage: mypy [-h] [-v] [-V] [more options; see below] alright, but when I invoke mypy on a program I get:

mypy: "..\..\..\..\tmp\tmp\mypy\mypy\typeshed\stdlib\abc.pyi" shadows library module "abc"
note: A user-defined top-level module with name "abc" is not supported

Also, if I try installing master instead of v1.15.0, it silently exits. Whether I do an editable or regular install.

Trying to pipx install . leads to

mypy: "test-data\unit\lib-stub\typing_extensions.pyi" shadows library module "typing_extensions"
note: A user-defined top-level module with name "typing_extensions" is not supported

Unless anybody else has these problems, I'm just going to assume something on my machine has gotten misconfigured over time, possibly the PYTHONPATH or similar, and close this issue.

@emmatyping
Copy link
Member

Can you see if you have a .pth file in the venv directory? Also are you installing into pipx from inside an activated venv? Can you also run echo %PYTHONPATH% (or echo $env:PYTHONPATH)?

@wyattscarpenter
Copy link
Contributor Author

  1. There are several files ending with the pth file extension in the venv directory, although none at the root level.
  2. No, I don't think so.
  3. echo %PYTHONPATH% produces %PYTHONPATH%. echo $env:PYTHONPATH produces $env:PYTHONPATH

I doubt it's worth trying to troubleshoot this, but thanks for the effort 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-developer Issues relevant to mypy developers
Projects
None yet
Development

No branches or pull requests

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy