Skip to content

venv issues with iCloud Documents #133028

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
1000100101011 opened this issue Apr 26, 2025 · 2 comments
Closed

venv issues with iCloud Documents #133028

1000100101011 opened this issue Apr 26, 2025 · 2 comments
Labels
OS-mac stdlib Python modules in the Lib dir topic-venv Related to the venv module type-bug An unexpected behavior, bug, or error

Comments

@1000100101011
Copy link

1000100101011 commented Apr 26, 2025

Bug report

Bug description:

This may be an odd edge case, and not sure what the "right" solution is...

If a user has "Desktop & Documents" folders synced with iCloud, and has more than one Mac, and different local usernames on each Mac, then virtual environments created on one Mac don't work on the other Mac.

It seems obvious now that I've dug into this that something would break in this scenario, but also, it wasn't immediately obvious to me why things were failing.

To recreate:
On Mac 1 with local-username-1 syncing "Documents" to iCloud Account:

~/Documents>  python3 -m venv <venv_name>
~/Documents>  cd <venv_name>
~/Documents/<venv_name>  vim anything.py  (write/save something)
~/Documents/<venv_name>  source bin/activate
~/Documents/<venv_name>  python anything.py  (It runs!)

On Mac 2 with local-username-2 syncing "Documents" to SAME iCloud Account:

~/Documents>  cd <venv_name>
~/Documents/<venv_name>  source bin/activate
~/Documents/<venv_name>  python anything.py  (It fails, "command not found: python")

Possible fix(?):
Change the creation of the activate script so that the VIRTUAL_ENV export statement uses the "USERNAME" environment variable:
export VIRTUAL_ENV='/Users/'${USERNAME}'/Documents/venv_name

I tested this, and it worked for me. I've tried to think of other cases where this change might cause problems, and none come to mind. But I fully accept that this may have major issues I'm oblivious to. Thoughts?

CPython versions tested on:

3.13

Operating systems tested on:

macOS

@1000100101011 1000100101011 added the type-bug An unexpected behavior, bug, or error label Apr 26, 2025
@ZeroIntensity ZeroIntensity added topic-venv Related to the venv module OS-mac labels Apr 26, 2025
@picnixz picnixz added the stdlib Python modules in the Lib dir label Apr 26, 2025
@corona10
Copy link
Member

cc @python/macos-team

@ned-deily
Copy link
Member

ned-deily commented Apr 28, 2025

Thanks for the report. This behavior has come up before in other issues (for example, #81145) and is not limited to the context of macOS or macOS iCloud file sharing. In general, venvs are not designed to be shared like this. While setting VIRTUAL_ENV may help for some uses, it doesn't solve all of the problems of trying to share. For example, when installing Python packages in a venv that has scripts, installers like pip may rewrite the "shebang" line of the script to hardcode the absolute execution path:

#!/Users/nad/xyz/bin/python

and, as these are generally launched directly by the operating system rather than through a shell, even adding a environment variable reference like ${USERNAME} wouldn't work.

There may also be the issue of ensuring that all systems attempting to use the shared venv have compatible Python installations as venvs typically use a system or other system-wide installation of Python that would not necessarily be shared or the same version.

@ned-deily ned-deily closed this as not planned Won't fix, can't repro, duplicate, stale Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-mac stdlib Python modules in the Lib dir topic-venv Related to the venv module type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants