资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

python建立venv虚拟环境的方法

这篇文章将为大家详细讲解有关python建立venv虚拟环境的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

站在用户的角度思考问题,与客户深入沟通,找到滨江网站设计与滨江网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站设计制作、成都网站设计、企业官网、英文网站、手机端网站、网站推广、申请域名、网络空间、企业邮箱。业务覆盖滨江地区。

创建虚拟环境

在当前目录创建虚拟环境:

$ python -m venv .1

下面是”venv”的详细使用参数:

usage: venv [-h] [--system-site-packages] [--symlinks] [--clear]
            [--upgrade] [--without-pip] 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 access to the global site-packages dir to the                         
  virtual environment.
  --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 environment directory if it already exists.                        
                         If not specified and the directory exists, an error is
                         raised.
  --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)

激活虚拟环境

在Posix标准平台下:

$ source /bin/activate

在Windows cmd下:

C:> /Scripts/activate.bat

在Windows PowerShell下:

PS C:> /Scripts/Activate.ps1

测试虚拟环境

激活虚拟环境后,在命令行会提示当前虚拟环境的名称,就表示激活成功了。

在当前虚拟环境中安装numpy:

$ pip install numpy

当前安装的numpy包与系统中的不会冲突,下面进行测试:

$ python
>>> import numpy
>>> print(numpy)

如果输出了numpy的包路径就表示一切正常。


关于python建立venv虚拟环境的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


本文标题:python建立venv虚拟环境的方法
分享URL:http://cdkjz.cn/article/jhojcs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220