"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 Create Virtualenv to Import Select Packages from Base Python Installation?

How to Create Virtualenv to Import Select Packages from Base Python Installation?

Published on 2024-11-01
Browse:807

How to Create Virtualenv to Import Select Packages from Base Python Installation?

Creating Virtualenvs to Inherit Specific Packages from the Base Python Installation

In the realm of Python development, the use of virtualenvs is commonplace to isolate package dependencies and maintain project-specific environments. However, there may arise situations where you desire a virtualenv containing only a select few libraries from your global site-packages. This question explores a method to achieve this endeavor.

To elaborate, the objective is to import specific packages, such as matplotlib, into a virtualenv during its creation. However, installing packages like matplotlib through pip or easy_install can be inefficient due to missing Fortran compiler libraries. Therefore, the traditional approach has involved manual copying of libraries from the base Python installation to the virtualenv.

However, this method results in the inability to register manually imported links using yolk, which lists available libraries in the virtualenv. The question seeks a more selective alternative to the --system-site-packages flag.

The solution lies in utilizing the --system-site-packages flag to create the virtualenv, which allows it to inherit the global site-packages. Once the virtualenv is active, you can utilize pip install --ignore-installed or pip install -I to install packages within the virtualenv, overriding existing system-wide versions.

This approach allows for a tailored virtualenv that includes desired packages while still providing isolation from the global Python installation.

Release Statement This article is reprinted at: 1729215375 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