使用venv创建虚拟环境

使用venv创建虚拟环境

python3.3 之后venv已经作为标准库嵌入到了python中,而之前的版本需要借助virtualenv这个第三方库来实现。

在终端中使用python -m venv -h可以显示venv工具的用法。

C:\Users\mango>python -m venv -h
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip]
            [--prompt PROMPT] [--upgrade-deps]
            ENV_DIR [ENV_DIR ...]

Creates virtual Python environments in one or more target directories.

positional arguments:
  ENV_DIR               A directory to create the environment in.

optional arguments:
  -h, --help            show this help message and exit
  --system-site-packages
                        Give the virtual environment access to the system site-packages dir.
  --symlinks            Try to use symlinks rather than copies, when symlinks are not the default for the platform.
  --copies              Try to use copies rather than symlinks, even when symlinks are the default for the platform.
  --clear               Delete the contents of the environment directory if it already exists, before environment
                        creation.
  --upgrade             Upgrade the environment directory to use this version of Python, assuming Python has been
                        upgraded in-place.
  --without-pip         Skips installing or upgrading pip in the virtual environment (pip is bootstrapped by default)
  --prompt PROMPT       Provides an alternative prompt prefix for this environment.
  --upgrade-deps        Upgrade core dependencies: pip setuptools to the latest version in PyPI

Once an environment has been created, you may wish to activate it, e.g. by sourcing an activate script in its bin
directory.

C:\Users\mango>

介绍的两个选项:
--system-site-packages代表使用全局环境中的第三方库(否则虚拟环境直接是纯洁的第三方库)
--without-pip代表不安装pip(一般都是要装的,所以默认就行)

创建虚拟环境

所以正常创建虚拟环境指令如下:python -m venv 安装路径

在当前目录下安装venvdemo这个虚拟环境

python -m venv venvtorch
posted @ 2023-03-01 23:27  周XX  阅读(199)  评论(0编辑  收藏  举报