Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:45:56+00:00 2026-05-30T09:45:56+00:00

I have a python library that has a dependency on importlib . importlib is

  • 0

I have a python library that has a dependency on importlib. importlib is in the standard library in Python 2.7, but is a third-party package for older pythons. I typically keep my dependencies in a pip-style requirements.txt. Of course, if I put importlib in here, it will fail if installed on 2.7. How can I conditionally install importlib only if it’s not available in the standard lib?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:45:58+00:00Added an answer on May 30, 2026 at 9:45 am

    I don’t think this is possible with pip and a single requirements file. I can think of two options I’d choose from:

    Multiple requirements files

    Create a base.txt file that contains most of your packages:

    # base.txt
    somelib1
    somelib2
    

    And create a requirements file for python 2.6:

    # py26.txt
    -r base.txt
    importlib
    

    and one for 2.7:

    # py27.txt
    -r base.txt
    

    Requirements in setup.py

    If your library has a setup.py file, you can check the version of python, or just check if the library already exists, like this:

    # setup.py
    from setuptools import setup
    install_requires = ['somelib1', 'somelib2']
    
    try:
        import importlib
    except ImportError:
        install_requires.append('importlib')
    
    setup(
        ...
        install_requires=install_requires,
        ...
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have renamed a python class that is part of a library. I am
I'm trying to use a Python library written in C that has no documentation
Does anyone know of a python library that has DTW implementation? mlpy seems to
I have a project that has code which will communicate with a python script
I have a class that I'm testing which has as a dependency another class
I am documenting a library that has a Python component and a JavaScript component.
Does Python have a unit testing framework compatible with the standard xUnit style of
I have a simple python script that updates that statuses of justin.tv streams in
I have python code that contains the following code. d = {} d[(0,0)] =
The Python library NetworkX has a fancy animated graph on their home page .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.