Welcome to the Python environment setup tutorial! If you are new to Python or need to set up your Python environment, this guide will help you get started.
安装 Python
The first step is to install Python on your system. You can download the latest version of Python from the official Python website. Make sure to select the version that matches your operating system.
配置 Python 环境变量
After installing Python, you need to configure the environment variables. This allows you to run Python from the command line. The steps to configure environment variables vary depending on your operating system.
- Windows: Open the System Properties window, go to the Advanced tab, and click on "Environment Variables".
- macOS/Linux: Open the Terminal and run the appropriate command for your system.
使用虚拟环境
It is recommended to use virtual environments for your Python projects. This allows you to manage dependencies for each project separately. You can create a virtual environment using the following command:
python -m venv myenv
To activate the virtual environment, use the following command:
- Windows:
myenv\Scripts\activate
- macOS/Linux:
source myenv/bin/activate
安装依赖
Once your virtual environment is activated, you can install dependencies using pip
. For example, to install the requests
library, run:
pip install requests
验证安装
To verify that everything is set up correctly, run the following command:
python --version
This should display the version of Python you have installed.
扩展阅读
For more information on Python and its ecosystem, check out the following resources: