Skip to content

venv issues with iCloud Documents #133028

Closed as not planned
Closed as not planned
@1000100101011

Description

@1000100101011

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-macstdlibPython modules in the Lib dirtopic-venvRelated to the venv moduletype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions