0Pricing
MLOps Academy · 课时

使用虚拟环境隔离项目

使用 venv 和 conda,避免项目相互冲突

使用虚拟环境隔离项目 是 CoddyKit 上的免费 MLOps Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 MLOps Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 MLOps Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

One Python, Many Projects

Install everything into one global Python and projects start fighting over versions. A virtual environment gives each project its own private space. 🧪

What venv Actually Does

A venv is just a folder holding its own Python and packages. Activate it and pip installs land there, not system-wide.

Create One

The built-in venv module makes an environment in a folder you name. Here it lands in a folder called .venv.

python -m venv .venv

Activate It

Activating puts that environment first on your path, so python and pip now point inside it instead of the system.

source .venv/bin/activate

Confirm You Are Inside

Run which python and you should see the path to your .venv folder. That proves installs will stay isolated.

which python

Leave When Done

The deactivate command drops you back to the system Python. Your project packages stay safely tucked in the folder.

deactivate

Never Commit the Folder

The .venv folder is large and machine-specific, so add it to .gitignore. Commit requirements.txt instead and rebuild anywhere.

.venv/

Conda Joins the Party

conda creates environments too, and it can manage non-Python tools like CUDA. That makes it popular for heavy ML and GPU work.

conda create -n mlops python=3.11

Pin the Python Version

Different Python versions can change behavior, so pin one per environment. Conda makes the Python version part of the create command.

One Env Per Project

Give each project its own environment. Then upgrading a library for one project can never silently break another.

Share It Reproducibly

Export your conda env to a YAML file so a teammate rebuilds the exact same setup with one command.

conda env export > environment.yml

Quick Check

What is the main reason to use a separate virtual environment per project?

Recap

You can now create a venv or conda env, activate it, gitignore the folder, pin Python, and export the setup so it rebuilds anywhere. 🧰

常见问题解答

「使用虚拟环境隔离项目」课时是免费的吗?

是的 — 「使用虚拟环境隔离项目」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 MLOps Academy 课程的其余内容,请升级到 CoddyKit PRO。 MLOps Academy 课程共包含 4 节课。

「使用虚拟环境隔离项目」这节课中我会学到什么?

使用 venv 和 conda,避免项目相互冲突 你通过在浏览器中直接运行的动手代码来练习 MLOps Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 MLOps Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 MLOps Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「使用虚拟环境隔离项目」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 MLOps Academy 课中编写并运行代码吗?

能。每节 MLOps Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 使用 requirements.txt 固定依赖版本
  2. 使用虚拟环境隔离项目
  3. 固定随机种子,实现可重复运行
  4. 记录完整运行配置
← 返回 MLOps Academy