-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
uv run --project
doesn't allow resolving module imports on windows
#12270
Comments
uv run --project
doesn't allow resolving module importsuv run --project
doesn't allow resolving module imports on windows
Isn't |
On macOS, running a script from a subfolder breaks module imports from the rest of the app as the python interpreter runs from the subfolder environment instead of the root project folder. The solution I found to this issue was using the On windows, both give the same result, which is the following error : In my opinion, the best solution would be not needing to use the |
Not able to reproduce on Windows 11. Folder structure: project/
├── app/
| └── foo.py
├── scripts/
| └── test.py
└── pyproject.toml foo.py def bar():
print("bar") test.py from app.foo import bar
bar() Running |
I reproduced your example and still get the same error on Windows 11. What are the contents of your pyproject.toml ? |
pyproject.toml [project]
name = "project"
version = "0.1.0"
description = "Project"
requires-python = ">=3.12" Note that I have placed the venv inside the project root and it is active before running the command, if that matters. |
The only difference is that I was using python 3.13 instead of 3.12, but i tried changing the version and I still get the same result. I am using a .venv placed in the project root as well. Any ideas for a workaround ? |
Adding this to the pyproject.toml file [project.scripts]
test = "scripts.test:main"
[build-system]
requires = ["uv_build"]
build-backend = "uv_build"
[tool.uv.build-backend]
module-root = ""
module-name = "app" (placing the |
Thanks a lot, this solution does indeed fix all my issues on both OSes, and it is much more elegant than what I was doing before. You can close this issue if everything else is expected behaviour. |
Summary
In my python project, I have a
scripts
folder where I keep various utilities that need to import code from the mainapp
folder. When running it on macOS, I just useuv run scripts/test.py --project .
and everything works as expected. On my windows system, when I tryuv run scripts\test.py --project .
i get the following error :ModuleNotFoundError: No module named 'app'
.I tried using an absolute path instead and various tricks to make it work, and also using the
--folder
argument instead, but nothing helps. Am I misunderstanding something or is this a bug ?Platform
Windows 11 x86_64
Version
0.6.6
Python version
3.13.2
The text was updated successfully, but these errors were encountered: