<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>技巧 - 标签 - Vindrin</title><link>https://vindrin.top/zh-cn/tags/%E6%8A%80%E5%B7%A7/</link><description>技巧 - 标签 - Vindrin</description><generator>Hugo -- gohugo.io</generator><language>zh-CN</language><managingEditor>vindrin@outlook.com (Vindrin)</managingEditor><webMaster>vindrin@outlook.com (Vindrin)</webMaster><lastBuildDate>Tue, 03 Feb 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://vindrin.top/zh-cn/tags/%E6%8A%80%E5%B7%A7/" rel="self" type="application/rss+xml"/><item><title>Python 虚拟环境详解</title><link>https://vindrin.top/zh-cn/posts/python-venv-guide/</link><pubDate>Tue, 03 Feb 2026 00:00:00 +0000</pubDate><author>vindrin@outlook.com (Vindrin)</author><guid>https://vindrin.top/zh-cn/posts/python-venv-guide/</guid><description><![CDATA[<h1 id="python-虚拟环境详解">Python 虚拟环境详解</h1>
<p>如果你曾经因为全局升级某个包把项目搞崩了，那你就需要虚拟环境了。</p>
<h2 id="什么是虚拟环境">什么是虚拟环境？</h2>
<p>虚拟环境是一个隔离的 Python 安装——它有自己独立的 <code>pip</code> 和包，完全和系统 Python 分开。</p>
<h2 id="创建虚拟环境">创建虚拟环境</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="复制到剪贴板"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">python -m venv .venv
</span></span><span class="line"><span class="cl"><span class="nb">source</span> .venv/bin/activate    <span class="c1"># Linux/macOS</span>
</span></span><span class="line"><span class="cl">.venv<span class="se">\S</span>cripts<span class="se">\a</span>ctivate       <span class="c1"># Windows</span></span></span></code></pre></div></div>
<h2 id="安装包">安装包</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="复制到剪贴板"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pip install requests numpy pandas
</span></span><span class="line"><span class="cl">pip freeze &gt; requirements.txt</span></span></code></pre></div></div>
<h2 id="在别处恢复">在别处恢复</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="复制到剪贴板"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">python -m venv .venv
</span></span><span class="line"><span class="cl">pip install -r requirements.txt</span></span></code></pre></div></div>
<h2 id="配合-conda-使用">配合 conda 使用</h2>
<p>如果你用 conda，<code>conda create -n myenv python=3.11</code> 也是同样的隔离效果。</p>]]></description></item></channel></rss>