Create a Python virtual environment (quick)

When working with Python, it’s best practice to use a separate virtual environment for each project to avoid dependency conflicts. Tools like PyCharm create virtual environments automatically, but you can just as easily do it via the command line:

  1. cd to your project root and create a new virtual environment

    Running this command will create a .venv folder (a common name, but you can customize it if needed):

    python3 <span>-m</span> venv .venv
    python3 <span>-m</span> venv .venv
    python3 -m venv .venv
  2. Activate the virtual environment

    <span>source</span> .venv/bin/activate
    <span>source</span> .venv/bin/activate
    source .venv/bin/activate
  3. Once activated, your console should look like this:

    <span>(</span>.venv<span>)</span> <user>@<computer> <FolderName>
    <span>(</span>.venv<span>)</span> <user>@<computer> <FolderName>
    (.venv) <user>@<computer> <FolderName>

You can leave the virtual environment by executing deactivate.

原文链接:Create a Python virtual environment (quick)

© 版权声明
THE END
喜欢就支持一下吧
点赞13 分享
pencil and a dream can take you anywhere.
拿起笔,写下你的梦想,你的人生就从此刻起航
评论 抢沙发

请登录后发表评论

    暂无评论内容