惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Troy Hunt's Blog
F
Fortinet All Blogs
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
The Register - Security
The Register - Security
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
V
Vulnerabilities – Threatpost
S
Securelist
S
SegmentFault 最新的问题
T
Threat Research - Cisco Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Privacy International News Feed
S
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
美团技术团队
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google Online Security Blog
Google Online Security Blog
M
MIT News - Artificial intelligence
U
Unit 42
V
V2EX
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
B
Blog
博客园 - 叶小钗
Attack and Defense Labs
Attack and Defense Labs
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
博客园 - Franky
Engineering at Meta
Engineering at Meta
Schneier on Security
Schneier on Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Blog of Author Tim Ferriss
IT之家
IT之家
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
Martin Fowler
Martin Fowler
SecWiki News
SecWiki News

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Virtual Environments: Why Your Projects Keep Breaking Each Other
Akhilesh · 2026-05-04 · via DEV Community

You install NumPy for Project A. Works great.

Six months later you start Project B. It needs a newer version of NumPy with features that did not exist before. You upgrade. Project B works.

You go back to Project A. It breaks. The new NumPy version changed something your old code depended on.

You downgrade NumPy. Project A works again. Project B breaks.

You go in circles. Neither project is stable. Your global Python installation is a mess of conflicting requirements.

This is the dependency hell that every Python developer hits eventually. Virtual environments are the solution. One isolated environment per project. Each with its own packages, its own versions, no conflict possible.


What a Virtual Environment Actually Is

A virtual environment is a folder. Inside that folder lives a complete, self-contained Python installation: the Python interpreter, pip, and all the packages you install while the environment is active.

When you activate an environment, your terminal uses the Python and pip inside that folder instead of the global ones. Install something while active and it goes into the folder. Deactivate and you are back to the global installation. The folder's packages are gone from view.

Nothing is shared between environments. NumPy 1.20 in one environment and NumPy 1.26 in another coexist perfectly because they live in different folders.


Creating and Using a Virtual Environment

python -m venv venv

Enter fullscreen mode Exit fullscreen mode

This creates a folder called venv in your current directory. The folder contains a full Python installation.

Activate it:

# Mac and Linux
source venv/bin/activate

# Windows Command Prompt
venv\Scripts\activate.bat

# Windows PowerShell
venv\Scripts\Activate.ps1

Enter fullscreen mode Exit fullscreen mode

Your terminal prompt changes to show the environment name:

(venv) user@machine:~/my_project$

Enter fullscreen mode Exit fullscreen mode

The (venv) prefix tells you the environment is active. Every pip install now goes into this environment, not the global Python.

pip install pandas numpy matplotlib scikit-learn

Enter fullscreen mode Exit fullscreen mode

These install only into the venv folder. No other project is affected.

Deactivate when done:

deactivate

Enter fullscreen mode Exit fullscreen mode

The (venv) prefix disappears. You are back to global Python.


requirements.txt: The File That Recreates Everything

Once you have installed your packages, save them:

pip freeze > requirements.txt

Enter fullscreen mode Exit fullscreen mode

Open requirements.txt and it looks like this:

joblib==1.3.2
matplotlib==3.8.2
numpy==1.26.3
pandas==2.1.4
pillow==10.2.0
scikit-learn==1.3.2
scipy==1.12.0
seaborn==0.13.1

Enter fullscreen mode Exit fullscreen mode

Every package and its exact version. On a new machine, or when a collaborator clones your project, they recreate the exact same environment:

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Enter fullscreen mode Exit fullscreen mode

Three commands. Identical environment. Every package at the exact version you developed with.

This is reproducibility. A year from now, you or anyone else can clone your project, run those three commands, and have everything working exactly as it did today.


What Goes in .gitignore

The venv folder itself should never go into Git. It is large (hundreds of megabytes), platform-specific, and completely regenerable from requirements.txt.

Your .gitignore should include:

venv/
.venv/
env/
ENV/

Enter fullscreen mode Exit fullscreen mode

What goes into Git: the requirements.txt file. That is all you need to recreate the environment.

git add requirements.txt
git commit -m "Add requirements.txt with project dependencies"

Enter fullscreen mode Exit fullscreen mode


Conda: The Alternative Worth Knowing

venv is built into Python and handles Python packages. Conda handles both Python packages and non-Python dependencies (C libraries, CUDA, R packages, etc.).

If you install Anaconda or Miniconda (the lightweight version):

conda create -n ml_env python=3.11
conda activate ml_env
conda install numpy pandas scikit-learn
pip install plotly streamlit

Enter fullscreen mode Exit fullscreen mode

Conda environments work the same way as venv: isolated, per-project, reproducible. The advantage is that Conda can install things like CUDA dependencies and compiled libraries that pip sometimes cannot handle cleanly.

Save a Conda environment:

conda env export > environment.yml

Enter fullscreen mode Exit fullscreen mode

Recreate it:

conda env create -f environment.yml

Enter fullscreen mode Exit fullscreen mode

For data science and AI work, Conda handles GPU dependencies (CUDA, cuDNN) more reliably than pure pip. When you reach the deep learning phase and need specific CUDA versions, Conda is the tool that makes installation clean.

For now, venv is simpler and sufficient for everything through Phase 6 of this series.


The Standard Project Structure

Every project you build from here should start the same way:

mkdir new_project
cd new_project
git init
python -m venv venv
source venv/bin/activate
pip install <your packages>
pip freeze > requirements.txt
echo "venv/" > .gitignore
echo "__pycache__/" >> .gitignore
echo "*.pyc" >> .gitignore
echo ".env" >> .gitignore
git add .
git commit -m "Initial project setup with virtual environment"

Enter fullscreen mode Exit fullscreen mode

Ten commands. Every new project. Five minutes. Then you have a clean, isolated, version-controlled starting point.

Structure the folders too:

my_project/
├── data/
│   ├── raw/
│   └── processed/
├── notebooks/
├── src/
├── tests/
├── venv/
├── .gitignore
├── requirements.txt
└── README.md

Enter fullscreen mode Exit fullscreen mode

data/raw/ for original downloaded data, never modified. data/processed/ for cleaned versions. notebooks/ for Jupyter notebooks. src/ for Python modules and scripts. tests/ for test files. This structure is recognizable to every data scientist and AI engineer who reviews your projects.


Managing Multiple Python Versions

Sometimes you need Python 3.9 for one project and Python 3.11 for another. pyenv handles this.

# Install pyenv (Mac/Linux)
curl https://pyenv.run | bash

# Install a specific Python version
pyenv install 3.11.7
pyenv install 3.9.18

# Set Python version for a specific directory
cd my_old_project
pyenv local 3.9.18

cd my_new_project
pyenv local 3.11.7

Enter fullscreen mode Exit fullscreen mode

pyenv local creates a .python-version file in the folder. Every time you cd into that folder, pyenv automatically switches to that Python version. Combined with venv, you have complete control over both Python version and package versions per project.

Windows users can use pyenv-win, same concept different installer.


The .env File: Environment Variables

API keys, database passwords, and configuration values should never be hardcoded in your Python files and never committed to Git.

Store them in a .env file:

DATABASE_URL=postgresql://user:password@localhost:5432/mydb
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
DEBUG=True
MODEL_PATH=/data/models/best_model.pkl

Enter fullscreen mode Exit fullscreen mode

Load them in Python with python-dotenv:

pip install python-dotenv

Enter fullscreen mode Exit fullscreen mode

from dotenv import load_dotenv
import os

load_dotenv()

api_key = os.getenv("OPENAI_API_KEY")
db_url  = os.getenv("DATABASE_URL")

print(f"API key loaded: {'yes' if api_key else 'no'}")

Enter fullscreen mode Exit fullscreen mode

Add .env to your .gitignore immediately. It should never, ever appear in your Git history. If you accidentally commit an API key, rotate it immediately and consider it compromised.

Commit a .env.example file instead:

DATABASE_URL=your_database_url_here
OPENAI_API_KEY=your_api_key_here
ANTHROPIC_API_KEY=your_api_key_here

Enter fullscreen mode Exit fullscreen mode

This tells collaborators what variables they need to set without exposing actual values.


Quick Reference

python -m venv venv              # create environment
source venv/bin/activate         # activate (Mac/Linux)
venv\Scripts\activate            # activate (Windows)
deactivate                       # deactivate
pip install package              # install into active env
pip freeze > requirements.txt    # save dependencies
pip install -r requirements.txt  # install from file
pip list                         # list installed packages
pip show pandas                  # details about one package
pip uninstall pandas             # remove a package

Enter fullscreen mode Exit fullscreen mode


A Resource Worth Reading

Hynek Schlawack, a well-respected Python developer, wrote "Hypermodern Python" on medium/his blog that covers virtual environments, dependency management, and project structure as professional Python developers actually use them. More advanced than this post but the right next step once the basics click. Search "Hynek Schlawack Hypermodern Python."

The Real Python tutorial called "Python Virtual Environments: A Primer" at realpython.com goes deep on how environments work under the hood, not just how to use them. Understanding why they work the way they do makes the occasional weird behavior (like forgetting to activate) immediately diagnosable. Search "Real Python virtual environments primer."


Try This

Create three separate project folders: phase6_ml, phase7_dl, and phase8_nlp.

For each one:

Initialize a Git repository. Create a virtual environment. Activate it. Install the packages appropriate for that phase (scikit-learn and pandas for ml, torch and torchvision for dl, transformers and tokenizers for nlp). Save a requirements.txt. Create a proper .gitignore. Create a basic README.md. Make an initial commit.

Verify isolation: activate the phase6_ml environment and confirm import torch fails. Activate phase7_dl and confirm import sklearn works. Each environment has exactly what it needs and nothing else.

These three repositories will hold your Phase 6, 7, and 8 projects. They are ready.


Phase 5 Is Now Actually Complete

Post 49 closes the tools phase. Git, GitHub, Jupyter, Colab, and virtual environments. The infrastructure is in place.

This is the last time you set up before doing. From here forward, every post builds something that runs, predicts, classifies, generates, or deploys.

Phase 6 starts next post. Machine learning from scratch, beginning with the most important question in the field: what does it actually mean for a machine to learn?