-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
If the working directory and the venv are on different disks, venv doesn't work in bash on Windows #103088
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
Comments
A POSIX shell delimits You can work around this issue by editing "{env_dir}/Scripts/activate" to replace the value of Maybe the "activate" script could detect MSYS or Cygwin and automatically translate the value of |
Thanks for the answer. My current workaround was to move venvs and code to the same disk. Now that you mention Cygwin I've tested the script with Cygwin's version of bash as well. The script fails because it contains \r. After applying dos2unix, it works but has the same issue as MSYS bash. Let's say I want to fix the script for everyone and not just for me. What would be the process, and what bash variants other than MSYS and Cygwin should I be aware of? |
Cygwin and MSYS2 are the common POSIX environments on Windows, other than WSL. Create a pull request that modifies the template script "Lib/venv/scripts/common/activate". cpython/Lib/venv/scripts/common/activate Lines 41 to 42 in e375bff
Apparently MSYS and Cygwin can be detected on bash using the if [ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ] ; then
export VIRTUAL_ENV=$(cygpath -u "__VENV_DIR__")
else
export VIRTUAL_ENV="__VENV_DIR__"
fi The venv module replaces the |
Thanks for your help. I didn't even know MSYS had cygpath, too. I've tested creating venvs in cmd and in MSYS2, then activating them in cmd, MSYS2, and cygwin, and looking at Two things I've noticed while doing this, not sure whether those are bugs or not:
|
It may depend on your Git settings, if you've cloned and built from source. Or maybe this file gets modified when venv copies it? @vsajip any thoughts?
Guessing this is a script launcher limitation, or maybe they aren't being generated properly in this scenario. In any case, it's external - I believe pip still gets their launchers from distlib? |
It doesn't only affect those who build from source: Python 3.11.1 that I installed from python.org has CR LF in It doesn't feel right to just clone everything with Unix line endings on Windows. I'm not sure whether all relevant programs can handle it correctly. On my computer, it seems to suffice if I add |
If that's added to I'd be more concerned about venv creation reading, modifying and writing the file with different line endings. If it doesn't do that, then modifying the attributes should be enough. |
The |
I've merged both fixes - any thoughts on backports? I think 3.11 is going to last long enough to be worth it, and while it won't help anyone who doesn't recreate their venvs, we'll have plenty of new users in the future. |
Well, buildbot failures mean we won't be backporting soon. Looks like:
The second issue only appears because the test is failing, so worth fixing that one first. |
I just checked, and the A quick test with a manual fresh checkout does end up with LF, so the buildbot tree is perhaps just git not adjusting an already checked out file. Once the parameter fix is addressed, I could manually flush the buildbot's 3.x tree to verify with a test run if it would help. |
I've checked again how it looks decoded vs. undecoded, found neither helpful and decided to remove the line itself from the error message and use the line number instead. See PR. |
This might be why the tests fail: #103500 (comment) |
It's not, the bit the docs are referring to aren't what matters here. We need the buildbots to do a clean checkout, that's all. |
You can flush it anyway, the test fix looks good, and the test will pass once the checkout is clean. Thanks @db3l! |
I flushed the 3.x tree on the I flushed everything, but I'm pretty sure just removing the single |
* main: pythongh-103479: [Enum] require __new__ to be considered a data type (pythonGH-103495) pythongh-103365: [Enum] STRICT boundary corrections (pythonGH-103494) pythonGH-103488: Use return-offset, not yield-offset. (pythonGH-103502) pythongh-103088: Fix test_venv error message to avoid bytes/str warning (pythonGH-103500) pythonGH-103082: Turn on branch events for FOR_ITER instructions. (python#103507) pythongh-102978: Fix mock.patch function signatures for class and staticmethod decorators (python#103228) pythongh-103462: Ensure SelectorSocketTransport.writelines registers a writer when data is still pending (python#103463) pythongh-95299: Rework test_cppext.py to not invoke setup.py directly (python#103316)
Hopefully this (#103524) approach to cleaning up all the buildbots will work. Would be nice to have something a bit narrower/faster, but this will do. |
Isn't that just using the PR branch directory on the buildbots and not any of the actual branch trees? Sort of a kludge, but perhaps actually touching the Or, any thought to just not going down this road, and expecting Cygwin users to use the igncr shell option? It's been a while since my Cygwin days but having to deal with CRLF scripts wasn't that uncommon. Separately, as it is, this change only fixes use under Cygwin with sh/bash (e.g., the csh script is still CRLF). |
Ah yeah, it will only touch the PR branches. Touching the file and merging it is probably the best option then. We've already merged the |
I just happened to notice the |
I don't think those even get copied for a venv on Windows, even in Cygwin. We moved |
But git bash is not Cygwin. |
Git-bash is based on msys2 [1], which is based on Cygwin [2]. [1] https://github.com/git-for-windows/git/wiki#about |
It's where the source code lives, ultimately. So most shell bugs/limitations that affect Cygwin also end up affecting msys2 and Git Bash, which makes them far more significant than "just" Cygwin. I'll update the attributes and touch the files. |
Also touches the files in no meaningful way to ensure they get updated when pulling
…03591) Also touches the affected files in meaningless ways to ensure they get updated when pulling
I'm going to consider this closed, unless someone really wants it backported to 3.11 |
Environment
path/to/python -m pip list
:Issue
When I create a venv on D: and use it from C:, executables like pip or python can't be found:
Linked PRs
The text was updated successfully, but these errors were encountered: