Usage
Managing Environments¶
Installing or updating packages can unintentionally change the versions of various packages in the environment, which can cause errors in programs that were previously running. For example, when using the Selenium web scraper, updating Selenium may change the API, resulting in errors that require debugging the program.
To avoid this situation, we can create a separate environment to run programs that depend on a fixed environment.
1) Creating a new environment
In this example, a new environment named "torch" is created, with Python version 3.11 specified.
2) Activating the environment
Too lazy to activate the environment every time
You can add conda activate [name]
as the last line in the ~/.bashrc
file to automatically activate a specific environment upon every connection.
3) Directly calling the environment
For example, if you don't want to enter the environment but need to directly call it to run a program, you can first obtain the path to the Python executable in that environment:
The which python
command will tell you the location of the Python executable in the "torch" environment. For example:
Now, we can use this Python executable to run our run.py
file:
4) Viewing environments
You can use the following command to check which environments are currently available in Conda:
5) Removing an environment
If an environment is no longer needed, it is recommended to remove it to save disk space and reduce the burden of managing environments.
This command will remove the "torch" environment.