将库安装到我的“基础"中吗?系统 Python 可以在 virtualenv 中使用吗? [英] Will libraries installed to my "base" system Python be available in a virtualenv?
问题描述
我是 Python 新手,所以请保持温和.
I'm new to python, so please be gentle.
在学习 Python 和编写我的前几个脚本时,我很快就忽略了关于 virtualenv
的任何教程部分,认为它不会在我的初级阶段给我带来任何好处.
In learning python and writing my first few scripts, I quickly glossed over any tutorial sections on virtualenv
, figuring it wouldn't provide me any benefit in my nascent stage.
我继续破解,安装软件包,同时使用 pip3 install package
I proceeded to hack away, installing packages as I went with pip3 install package
现在我已经构建了一些可能对我的组织有用的东西,我想分享它.在这种情况下,我想将其作为 Windows 可执行文件分发.
Now I've built something that is potentially useful to my organization, and I'd like to share it. In this case, I want to distribute it as a windows executable.
在构建这个发行版之前,我认为现在是时候从单个脚本到适当的 Python 项目进行下一次飞跃了.看起来 virtualenv
应该是其中的一部分.
Before building this distribution, I figure it's now time to take the next leap from individual scripts to proper python projects. It seems like virtualenv
should be part of that.
鉴于我已经在我的基本"python 环境中安装了许多软件包:为了在干净"的虚拟环境中进行开发,我是否需要以某种方式恢复"我的基本 python 环境(即卸载所有非标准包),或者 virtualenv
是否会将虚拟环境中的项目与安装到我的基本"环境的非标准包屏蔽?
Given that I've installed a number of packages to my "base" python environment: in order to do development in a "clean" virtual environment, do I need to somehow "revert" my base python environment (i.e. uninstall all non-standard packages), or will virtualenv
shield a project within a virtual environment from non-standard packages installed to my "base" environment?
推荐答案
如果您正在使用 venv
模块,则有 --system-site-packages
标志将授予创建的虚拟环境访问系统范围的站点包目录的权限:
If you are using the venv
module there is --system-site-packages
flag that will grant the created virtual environment access to the system-wide site-packages directory:
--system-site-packages
Give the virtual environment access to the system
site-packages dir.
这篇关于将库安装到我的“基础"中吗?系统 Python 可以在 virtualenv 中使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!