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

  • Home
  • SEARCH
  • 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 8472929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:12:37+00:00 2026-06-10T17:12:37+00:00

>>> import distutils.sysconfig >>> distutils.sysconfig.get_python_lib() /usr/lib/python2.7/dist-packages But I want this path: /usr/local/lib/python2.7/dist-packages . I

  • 0
>>> import distutils.sysconfig
>>> distutils.sysconfig.get_python_lib()
/usr/lib/python2.7/dist-packages

But I want this path: /usr/local/lib/python2.7/dist-packages.
I can’t use the sysconfig module because it is only supported on python2.7 and there is no PyPI download to that module. so I could not even use a requirements file to let other users download it with pip.

So, is there any way to get the path to my installed packages that works for Linux and OS X operating systems? (or even all Unix based os’s)

  • 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-10T17:12:38+00:00Added an answer on June 10, 2026 at 5:12 pm

    If you need the specific functionality of the get_python_lib function, the source for that module is fairly straightforward and doesn’t use any Python 2.7 specific syntax at all; you could simply backport it.

    You’d basically need the following definitions and two functions:

    import os
    import sys
    from distutils.errors import DistutilsPlatformError
    
    
    PREFIX = os.path.normpath(sys.prefix)
    EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
    
    
    def get_python_version():
        """Return a string containing the major and minor Python version,
        leaving off the patchlevel.  Sample return values could be '1.5'
        or '2.2'.
        """
        return sys.version[:3]
    
    def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
        """Return the directory containing the Python library (standard or
        site additions).
    
        If 'plat_specific' is true, return the directory containing
        platform-specific modules, i.e. any module from a non-pure-Python
        module distribution; otherwise, return the platform-shared library
        directory.  If 'standard_lib' is true, return the directory
        containing standard Python library modules; otherwise, return the
        directory for site-specific modules.
    
        If 'prefix' is supplied, use it instead of sys.prefix or
        sys.exec_prefix -- i.e., ignore 'plat_specific'.
        """
        if prefix is None:
            prefix = plat_specific and EXEC_PREFIX or PREFIX
    
        if os.name == "posix":
            libpython = os.path.join(prefix,
                                     "lib", "python" + get_python_version())
            if standard_lib:
                return libpython
            else:
                return os.path.join(libpython, "site-packages")
    
        elif os.name == "nt":
            if standard_lib:
                return os.path.join(prefix, "Lib")
            else:
                if get_python_version() < "2.2":
                    return prefix
                else:
                    return os.path.join(prefix, "Lib", "site-packages")
    
        elif os.name == "os2":
            if standard_lib:
                return os.path.join(prefix, "Lib")
            else:
                return os.path.join(prefix, "Lib", "site-packages")
    
        else:
            raise DistutilsPlatformError(
                "I don't know where Python installs its library "
                "on platform '%s'" % os.name)
    

    You can cut the long function down to just the branch you need for your platform, of course; for OS X that’d be:

    def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
        if prefix is None:
            prefix = plat_specific and EXEC_PREFIX or PREFIX
    
        libpython = os.path.join(prefix,
                                 "lib", "python" + get_python_version())
        if standard_lib:
            return libpython
        else:
            return os.path.join(libpython, "site-packages")
    

    Note that Debian patches this function to return dist-packages in the default case, this doesn’t apply to OS X.

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

Sidebar

Related Questions

from distutils.sysconfig import get_python_lib; print get_python_lib() Returns: /usr/lib/python2.6/site-packages import sys; print sys.path Returns: ['',
I guess this is a PATH/PYTHONPATH error, but my attempts failed so far to
My setup.py looks something like this: from distutils.core import setup setup( [...] install_requires=['gevent', 'ssl',
I'm using this code: code = 'import setuptools;__file__={0!r};execfile(__file__)'.format(os.path.join(path, 'setup.py')) args = ['install', '--single-version-externally-managed'] subprocess.check_call([sys.executable,
setup.py from distutils.core import setup import py2exe setup(console=['program.py']) The error Traceback (most recent call
import xlwt import xlrd import os.path import os print os.path.abspath(os.curdir) #Create workbook and worksheet
I wanted to learn how to create python packages, so I visited http://docs.python.org/distutils/index.html .
Can someone tell me what I'm doing wrong to package this as a module:
I have a very simple setup: from distutils.core import setup setup(name='myscripts', description='my scripts', author='Ago',
import subprocess subprocess.Popen(['C:\Program Files\Nuke6.1v3\\Nuke6.1.exe', '-t', 'C:\Users\user\Desktop\\server.py' I am currently using this to call server.py,

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.