"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Inherit Specific Packages in Virtualenv from Global Site-Packages?

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

Published on 2024-11-06
Browse:100

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:

virtualenv --system-site-packages

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:

pip install --ignore-installed 

or

pip install -I 

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.

Release Statement This article is reprinted at: 1729215676 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3