Skip to content

Conversation

Birnendampf
Copy link
Contributor

when trying to run a Textual app without activating the envirionment (out of laziness or in scripts) using e.g.

.venv/bin/textual run main.py

it will look up "python" in $PATH instead of using the one in .venv/. This results in it trying to run the app with the system interpreter and thus not being able to import Textual.
the reason for this is this line of code.

os.execvpe(sys.executable, ["python", *args], environment)

Apparently (I didn't know this either) the executable from args is used, not the one given to os.execvpe() , at least on linux, and since that is just "python" it is looked up in $PATH.
Also, there is no need to use execvpe() instead of execve() because sys.executable is always absolute

@willmcgugan
Copy link
Member

thanks

@willmcgugan willmcgugan merged commit cda808e into Textualize:main Oct 11, 2025
@willmcgugan
Copy link
Member

Actually, I don't think this is correct. There's no garantee that textual CLI is in the same venv -- and it doesn't have to be. So "textual run foo.py" should be equivalent to "python foo.py"

@Birnendampf
Copy link
Contributor Author

Oh that is true there might be a use case where somebody has textual-cli installed via pipx. Sorry didn't think about that, it seemed intuitive that textual cli would be where the application is

@willmcgugan
Copy link
Member

A completely reasonable assumption. I had a second thought after merging. Appreciate the PR.

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

Successfully merging this pull request may close these issues.

2 participants