How do I create a new PyTorch environment with Conda?
To create a new PyTorch environment, you can follow these steps:
- Open the terminal or command prompt and run the following command to create a new conda environment:
- Create a new environment called
with Python version . - In this case,
is the name you want to specify for the new environment, and is the Python version you want to use in the environment. For example, if you want to create an environment named pytorch_env and use Python version 3.7, you can run the following command: - Create a new environment named pytorch_env with Python version 3.7.
- Activate the newly created environment by running the following command.
- Activate the environment using “conda activate” followed by the name of the environment.
- For example, to activate an environment named pytorch_env, you can run the following command:
- activate the pytorch environment in conda
- Install PyTorch and other necessary dependencies. Activate the environment and run the following command to install PyTorch and other necessary dependencies:
- Install PyTorch, Torchvision, Torchaudio, and the appropriate CUDA toolkit version using Conda from the PyTorch channel.
- In this case, “
” is the CUDA version number you are using. If you are not using CUDA, you do not need to provide the cudatoolkit parameter. For example, to install Pytorch suitable for CUDA 11.1, you can run the following command: - Install PyTorch, torchvision, torchaudio, and cudatoolkit version 11.1 from the pytorch channel using conda.
- Create a Jupyter kernel (optional). If you want to use Jupyter Notebook or JupyterLab in a new environment, you can create a new Jupyter kernel by running the following command.
- Install the IPython kernel for the given environment with a specific display name.
- In Jupyter,
refers to the name of your environment, while is the name you want to show for the kernel in Jupyter. For example, to display a kernel named “pytorch_env” in Jupyter, you can run the following command: - Install the PyTorch Environment kernel for Python using the command: python -m ipykernel install –user –name=pytorch_env –display-name=”PyTorch Environment”
By now, you should have successfully created a new PyTorch environment. You can run Python scripts or start a Jupyter Notebook using the environment after activating it. Remember to activate the environment before using it.