Heim  >  Artikel  >  Backend-Entwicklung  >  Wie erbe ich bestimmte Pakete in Virtualenv von globalen Site-Paketen?

Wie erbe ich bestimmte Pakete in Virtualenv von globalen Site-Paketen?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-18 09:52:02606Durchsuche

How to Inherit Specific Packages in Virtualenv from Global Site-Packages?

Inheriting Specific Packages in Virtualenv from Global Site-Packages

To enhance the functionality of a virtual environment (virtualenv), you may desire to inherit specific packages from the global site-packages directory. This approach allows you to selectively incorporate vital libraries into your virtualenv without installing them directly.

Inheritance Method

To achieve this inheritance, create a new virtualenv using the following command:

<code class="bash">virtualenv --system-site-packages</code>

This command enables the virtualenv to access packages installed in the system's global site-packages directory.

Installing Within Virtualenv

Once the virtualenv is active, you can install packages specific to the virtualenv using the following commands:

<code class="bash">pip install --ignore-installed <package-name></code>

or

<code class="bash">pip install -I <package-name></code>

These commands will install the specified packages locally within the virtualenv, even if a system-wide version exists.

Package Precedence

By default, the Python interpreter will search for modules first in the virtualenv's package directory. This ensures that the packages installed locally take precedence over any global versions. Therefore, the packages inherited from the global site-packages effectively become shadowed within the virtualenv.

Das obige ist der detaillierte Inhalt vonWie erbe ich bestimmte Pakete in Virtualenv von globalen Site-Paketen?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn