[Easy] Add notes for setting up dev venv with specific Python version (#164214)

Resolves https://github.com/pytorch/pytorch/issues/164010#issuecomment-3340751377

Pull Request resolved: https://github.com/pytorch/pytorch/pull/164214
Approved by: https://github.com/ezyang
ghstack dependencies: #162324
This commit is contained in:
Xuehai Pan
2025-09-30 14:56:07 +08:00
committed by PyTorch MergeBot
parent eca6ac2293
commit 17ab99463a
2 changed files with 27 additions and 13 deletions

View File

@ -7,12 +7,12 @@ binaries into the repo.
You can use this script to check out a new nightly branch with the following::
$ ./tools/nightly.py checkout -b my-nightly-branch
$ source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
$ source venv/bin/activate # or `. .\venv\Scripts\activate` on Windows
Or if you would like to check out the nightly commit in detached HEAD mode::
$ ./tools/nightly.py checkout
$ source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
$ source venv/bin/activate # or `. .\venv\Scripts\activate` on Windows
Or if you would like to reuse an existing virtual environment, you can pass in
the prefix argument (--prefix)::
@ -23,18 +23,24 @@ the prefix argument (--prefix)::
To install the nightly binaries built with CUDA, you can pass in the flag --cuda::
$ ./tools/nightly.py checkout -b my-nightly-branch --cuda
$ source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
$ source venv/bin/activate # or `. .\venv\Scripts\activate` on Windows
To install the nightly binaries built with ROCm, you can pass in the flag --rocm::
$ ./tools/nightly.py checkout -b my-nightly-branch --rocm
$ source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
$ source venv/bin/activate # or `. .\venv\Scripts\activate` on Windows
You can also use this tool to pull the nightly commits into the current branch as
well. This can be done with::
$ ./tools/nightly.py pull
$ source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows
$ source venv/bin/activate # or `. .\venv\Scripts\activate` on Windows
To create the virtual environment with a specific Python interpreter, you can
pass in the --python argument::
$ ./tools/nightly.py --python /path/to/python3.12
$ source venv/bin/activate # or `. .\venv\Scripts\activate` on Windows
Pulling will recreate a fresh virtual environment and reinstall the development
dependencies as well as the nightly binaries into the repo directory.
@ -308,7 +314,7 @@ class Venv:
"""Get the activation script for the virtual environment."""
if WINDOWS:
# Assume PowerShell
return self.prefix / "Scripts" / "Activate.ps1"
return self.prefix / "Scripts" / "activate"
# Assume POSIX-compliant shell: Bash, Zsh, etc.
return self.prefix / "bin" / "activate"
@ -317,7 +323,7 @@ class Venv:
"""Get the command to activate the virtual environment."""
if WINDOWS:
# Assume PowerShell
return f'& "{self.activate_script}"'
return f'. "{self.activate_script}"'
# Assume Bash, Zsh, etc.
# POSIX standard should use dot `. venv/bin/activate` rather than `source`
return f"source {shlex.quote(str(self.activate_script))}"