ty icon indicating copy to clipboard operation
ty copied to clipboard

Unresolved imports in projects on network drives

Open arvidmor opened this issue 2 months ago • 8 comments

Summary

At work, our workstations connect to internal servers for storing our daily work. We have several of these servers, which are all set up slightly differently, though I don't know the details of this (sorry). At least one of them uses a NetApp solution of some kind. The issue reproduces on all of them.

I cannot get ty to find any installed dependencies when the project is located on any of these network drives. My client is running Windows 11 Enterprise 23H2.

MRE

Setup a new project on a network drive and import a 3rd party package

$ uv init example
Initialized project `example` at `H:\example`
$ cd example && .venv/Scripts/activate.ps1
$ uv add openpyxl ty # or any other 3rd party package
$ echo "import openpyxl" > main.py

Run ty

$ ty check .
error[unresolved-import]: Cannot resolve imported module `openpyxl`
 --> main.py:1:8
  |
1 | import openpyxl
  |        ^^^^^^^^
  |
info: Searched in the following paths during module resolution:
info:   1. H:\example (first-party code)
info:   2. vendored://stdlib (stdlib typeshed stubs vendored by ty)
info:   3. \\?\UNC\servername.at.corp.se\home$\username\example\.venv\Lib\site-packages (site-packages)
info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment
info: rule `unresolved-import` is enabled by default

Additional information

Running ls on the site-packages path returns nothing. If the path doesn't exist it would normally print an error (I'm using powershell here).

$ ls \\?\UNC\servername.at.corp.se\home$\username\example\.venv\Lib\site-packages
$

But removing the "?\UNC" works:

$ ls \\servername.at.corp.se\home$\username\example\.venv\Lib\site-packages

    Directory: \\servername.at.corp.se\home$\username\example\.venv\Lib\site-packages

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          2025-12-18    11:44                __pycache__
d----          2025-12-18    11:44                et_xmlfile
d----          2025-12-18    11:41                et_xmlfile-2.0.0.dist-info
d----          2025-12-18    11:44                openpyxl
d----          2025-12-18    11:41                openpyxl-3.1.5.dist-info
d----          2025-12-18    11:48                ty
d----          2025-12-18    11:48                ty-0.0.3.dist-info
-a---          2025-12-18    11:41             18 _virtualenv.pth
-a---          2025-12-18    11:41           4342 _virtualenv.py

Version

0.0.3

arvidmor avatar Dec 18 '25 11:12 arvidmor

Hmm, I wonder where we get this path from. Can you run ty check -v and share the logs with us?

MichaReiser avatar Dec 18 '25 12:12 MichaReiser

Hmm, I wonder where we get this path from. Can you run ty check -v and share the logs with us?

Sure, here's the output of the command. If by 'logs' you're referring to something else, please point me in the right direction :)

(example) PS H:\example> ty check -v
INFO Defaulting to python-platform `win32`
INFO Python version: Python 3.13, platform: win32
INFO Indexed 1 file(s) in 0.033s
error[unresolved-import]: Cannot resolve imported module `openpyxl`
 --> main.py:1:8
  |
1 | import openpyxl
  |        ^^^^^^^^
  |
info: Searched in the following paths during module resolution:
info:   1. H:\example (first-party code)
info:   2. vendored://stdlib (stdlib typeshed stubs vendored by ty)
info:   3. \\?\UNC\servername.at.corp.se\home$\username\example\.venv\Lib\site-packages (site-packages)
info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment
info: rule `unresolved-import` is enabled by default

H: just points to my home directory on the server, hence the "home$\username".

arvidmor avatar Dec 18 '25 12:12 arvidmor

Hmm, sorry. I should have asked you to run ty check -vv to get more detailed logs.

MichaReiser avatar Dec 18 '25 12:12 MichaReiser

Alright, here they are!

(example) PS H:\example> ty check -vv
2025-12-18 13:35:18.8501786 DEBUG Version: 0.0.3 (fadfe0966 2025-12-17)
2025-12-18 13:35:18.8538037 DEBUG Architecture: x86_64, OS: windows, case-sensitive: unknown
2025-12-18 13:35:18.8538768 DEBUG Searching for a project in 'H:\example'
2025-12-18 13:35:18.8655172 DEBUG Resolving requires-python constraint: `>=3.13`
2025-12-18 13:35:18.8657147 DEBUG Resolved requires-python constraint to: 3.13
2025-12-18 13:35:18.8717641 DEBUG Project without `tool.ty` section: 'H:\example'
2025-12-18 13:35:18.8719901 DEBUG Searching for a user-level configuration at `C:\Users\username\AppData\Roaming\ty\ty.toml`
2025-12-18 13:35:18.8733746 INFO Defaulting to python-platform `win32`
2025-12-18 13:35:18.8735183 DEBUG Resolving `VIRTUAL_ENV` environment variable: H:\example\.venv
2025-12-18 13:35:18.8949458 DEBUG Attempting to parse virtual environment metadata at '\\?\UNC\servername.at.corp.se\home$\username\example\.venv\pyvenv.cfg'
2025-12-18 13:35:18.9279275 DEBUG Searching for site-packages directory in sys.prefix \\?\UNC\servername.at.corp.se\home$\username\example\.venv
2025-12-18 13:35:18.9434707 DEBUG Resolved site-packages directories for this virtual environment are: ["\\\\?\\UNC\\servername.at.corp.se\\home$\\username\\example\\.venv\\Lib\\site-packages"]
2025-12-18 13:35:18.944126 DEBUG Searching for real stdlib directory in sys.prefix C:\Users\username\AppData\Local\Programs\Python\Python313
2025-12-18 13:35:18.944381 DEBUG Resolved real stdlib path for this virtual environment is: C:\Users\username\AppData\Local\Programs\Python\Python313\Lib
2025-12-18 13:35:18.9504509 DEBUG Including `.` in `environment.root`
2025-12-18 13:35:18.9534431 DEBUG Adding first-party search path `H:\example`
2025-12-18 13:35:18.96296 DEBUG Using vendored stdlib
2025-12-18 13:35:18.9659672 DEBUG Adding site-packages search path `\\?\UNC\servername.at.corp.se\home$\username\example\.venv\Lib\site-packages`
2025-12-18 13:35:18.9789951 INFO Python version: Python 3.13, platform: win32
2025-12-18 13:35:18.979152 DEBUG Adding new file root '\\?\UNC\servername.at.corp.se\home$\username\example\.venv\Lib\site-packages' of kind LibrarySearchPath
2025-12-18 13:35:18.9800747 DEBUG Adding new file root 'H:\example' of kind Project
2025-12-18 13:35:18.9803392 DEBUG Starting main loop
2025-12-18 13:35:18.9804181 DEBUG Waiting for next main loop message.
2025-12-18 13:35:18.980524 DEBUG Checking all files in project 'example'
2025-12-18 13:35:19.0939531 DEBUG Skipping directory 'H:\example\.git' because it is excluded by a default or `src.exclude` pattern
2025-12-18 13:35:19.0959763 INFO Indexed 1 file(s) in 0.115s
2025-12-18 13:35:19.1025544 DEBUG Checking file 'H:\example\main.py'
2025-12-18 13:35:19.1141865 DEBUG Resolving dynamic module resolution paths
2025-12-18 13:35:19.1424371 DEBUG Module `openpyxl` not found in search paths
2025-12-18 13:35:19.1438959 DEBUG Module `openpyxl` not found while looking in parent dirs (neither stub nor real module file)
2025-12-18 13:35:19.1442785 DEBUG Checking all files took 0.048s
error[unresolved-import]: Cannot resolve imported module `openpyxl`
 --> main.py:1:8
  |
1 | import openpyxl
  |        ^^^^^^^^
  |
info: Searched in the following paths during module resolution:
info:   1. H:\example (first-party code)
info:   2. vendored://stdlib (stdlib typeshed stubs vendored by ty)
info:   3. \\?\UNC\servername.at.corp.se\home$\username\example\.venv\Lib\site-packages (site-packages)
info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment
info: rule `unresolved-import` is enabled by default

Found 1 diagnostic
2025-12-18 13:35:19.1453447 DEBUG Exiting main loop

arvidmor avatar Dec 18 '25 12:12 arvidmor

I suspect that ty gets all confused about H:\example\.venv expanding to \\?\UNC\servername.at.corp.se\home$\username\example\.venv\pyvenv.cfg. I would have to look back at why we canonicalize virtual environments in the first place. If not, that might be the easiest fix. It's also curious that we can't remove the UNC prefix.

But this will require me to set up a Windows network drive.

Just for completness, would you mind sharing what's in H:\example\.venv\Lib\site-packages (just a directory listing with dir)

MichaReiser avatar Dec 19 '25 12:12 MichaReiser

Hello, I'm having the exact same issue:

(copy-rated) PS Z:\Scripts\copy_rated> ty check
error[unresolved-import]: Cannot resolve imported module `filelock`
 --> copy_rated.py:7:6
  |
5 | from itertools import tee
6 |
7 | from filelock import FileLock
  |      ^^^^^^^^
  |
info: Searched in the following paths during module resolution:
info:   1. Z:\Scripts\copy_rated (first-party code)
info:   2. vendored://stdlib (stdlib typeshed stubs vendored by ty)
info:   3. \\?\UNC\SERVERNAME\E\Scripts\copy_rated\.venv\Lib\site-packages (site-packages)
info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment
info: rule `unresolved-import` is enabled by default

...

Found 4 diagnostics

(Extra unresolved imports removed from output)

striker4150 avatar Dec 21 '25 23:12 striker4150