简体   繁体   English

python虚拟环境中的标准库在哪里?

[英]Where is the standard library in python virtual environment?

I'm using Ubuntu system with python 3.5 installed by default. 我正在使用默认情况下安装了python 3.5的Ubuntu系统。

When I use the venv module to create virtual environment, I can't find the standard library in my virtual environment but only the binary file for python interpreter. 当我使用venv模块创建虚拟环境时,我无法在虚拟环境中找到标准库,只能找到python解释器的二进制文件。 However I can import standard library modules in my python script when I switch to use this virtual environment. 但是,当我切换为使用此虚拟环境时,可以在python脚本中导入标准库模块。

So how does venv work? 那么venv如何工作? Does the newly created virtual environment just use the standard library of the system python? 新创建的虚拟环境是否仅使用系统python的标准库? If so, what if I want to create a completely self-contained virtual environment? 如果是这样,如果我要创建一个完全独立的虚拟环境该怎么办? Is it possible to achieve this by the venv module? 是否可以通过venv模块实现此venv By the way, I used conda before. 顺便说一句,我以前用过conda conda can create virtual environment with python different with the system version. conda可以使用与系统版本不同的python创建虚拟环境。 Can venv do this job? venv可以做这项工作吗?

It's because venv uses the systems standard library. 这是因为venv使用系统标准库。 it will be a problem if you update actual Python because version mismatch can happen there. 如果您更新实际的Python,将会出现问题,因为版本不匹配可能会在那里发生。 Take a look at the following link you will get more information. 查看以下链接,您将获得更多信息。
https://virtualenv.pypa.io/en/stable/ https://virtualenv.pypa.io/en/stable/

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. 虚拟环境是通过为虚拟项目创建虚拟Python环境,从而将不同项目所需的依赖项保持在单独位置的工具。 It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable 它解决了“ Project X取决于版本1.x,但Project Y需要4.x”的难题,并使全局站点包目录保持清洁和可管理。

virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need. virtualenv创建一个文件夹,其中包含使用Python项目所需的所有必需可执行文件。

Since you are using python 3, Use the venv module, which you can install through apt-get. 由于您使用的是python 3,因此请使用venv模块,您可以通过apt-get安装它。

$ sudo apt-get install python3.5-venv

Then you can set up your virtual environment with 然后,您可以使用以下命令设置虚拟环境

$ pyvenv-3.5 /path/to/directory

and activate the environment with 并通过以下方式激活环境

$ source /path/to/directory/bin/activate

Also This may help you. 此外可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM