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 9162953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:20:10+00:00 2026-06-17T14:20:10+00:00

When using setuptools/distutils to build C libraries in Python $ python setup.py build the

  • 0

When using setuptools/distutils to build C libraries in Python

$ python setup.py build

the *.so/*.pyd files are placed in build/lib.win32-2.7 (or equivalent).

I’d like to test these files in my test suite, but I’d rather not hard code the build/lib* path. Does anyone know how to pull this path from distutils so I can sys.path.append(build_path) – or is there an even better way to get hold of these files? (without having installed them first)

  • 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-06-17T14:20:11+00:00Added an answer on June 17, 2026 at 2:20 pm

    You must get the platform that you are running on and the version of python you are running on and then assemble the name yourself. This is an internal detail of setuptools (based on the bundled version of distutils), and so is not guaranteed to be stable.

    To get the current platform, use sysconfig.get_platform(). To get the python version, use sys.version_info (specifically the first three elements of the returned tuple). On my system (64-bit linux with python 2.7.2) I get:

    >>> import sysconfig
    >>> import sys
    >>> sysconfig.get_platform()
    linux-x86_64
    >>> sys.version_info[:3]
    (2, 7, 2)
    

    Before setuptools 62.1

    The format of the lib directory is "lib.platform-versionmajor.versionminor" (i.e. only 2.7, not 2.7.2). You can construct this string using python’s string formatting methods:

    def distutils_dir_name(dname):
        """Returns the name of a distutils build directory"""
        f = "{dirname}.{platform}-{version[0]}.{version[1]}"
        return f.format(dirname=dname,
                        platform=sysconfig.get_platform(),
                        version=sys.version_info)
    

    After setuptools 62.1

    The directory above clashes with alternative python implementations like PyPy, so the internal build directory was made more specific using sys.implementation.cache_tag. The format of the lib directory is "lib.<platform>-<cachetag>". You can construct this string using python’s string formatting methods:

    def distutils_dir_name(dname):
        """Returns the name of a distutils build directory"""
        f = "{dirname}.{platform}-{cache_tag}"
        return f.format(dirname=dname,
                        platform=sysconfig.get_platform(),
                        cache_tag=sys.implementation.cache_tag)
    

    You can use this to generate the name of any of distutils build directory:

    >>> import os
    # Before Setuptools 62.1
    >>> os.path.join('build', distutils_dir_name('lib'))
    build/lib.linux-x86_64-3.9
    # After Setuptools 62.1
    >>> os.path.join('build', distutils_dir_name('lib'))
    build/lib.linux-x86_64-cpython39
    

    Note that Setuptools 62.1 is only available on Python 3.7+. Also, if you set SETUPTOOLS_USE_DISTUTILS=stdlib in your environment, then you will get the old behavior even in Setuptools 62.1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to call Python's distutils' or setuptools' setup() function in a slightly unconventional
I have a standard python package layout like this: setup.py - using setuptools README
I was writing a setup.py for a Python package using setuptools and wanted to
I was trying the python packaging using setuptools and to test I installed the
I'm trying to include some data files in a python package using the setuptools
I've produced a python egg using setuptools and would like to access it's metadata
I am currently coding setup.py using setuptools. And I want to copy the static
I have a very simple python package that I build into debian packages using
If one installs a python package using setuptools, then executes a method in that
I'm using setuptools 0.6 to package my code. By default when I type python

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.