[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

@ -81,7 +81,7 @@ git remote add upstream git@github.com:pytorch/pytorch.git
make setup-env make setup-env
# Or run `make setup-env-cuda` for pre-built CUDA binaries # Or run `make setup-env-cuda` for pre-built CUDA binaries
# Or run `make setup-env-rocm` for pre-built ROCm binaries # Or run `make setup-env-rocm` for pre-built ROCm binaries
source venv/bin/activate # or `& .\venv\Scripts\Activate.ps1` on Windows source venv/bin/activate # or `. .\venv\Scripts\activate` on Windows
``` ```
### Tips and Debugging ### Tips and Debugging
@ -182,28 +182,36 @@ You can use this script to check out a new nightly branch with the following:
```bash ```bash
./tools/nightly.py checkout -b my-nightly-branch ./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
``` ```
To install the nightly binaries built with CUDA, you can pass in the flag `--cuda`: To install the nightly binaries built with CUDA, you can pass in the flag `--cuda`:
```bash ```bash
./tools/nightly.py checkout -b my-nightly-branch --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`: To install the nightly binaries built with ROCm, you can pass in the flag `--rocm`:
```bash ```bash
./tools/nightly.py checkout -b my-nightly-branch --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: You can also use this tool to pull the nightly commits into the current branch:
```bash ```bash
./tools/nightly.py pull -p my-env ./tools/nightly.py pull
source my-env/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:
```bash
./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 Pulling will recreate a fresh virtual environment and reinstall the development

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