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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:42:39+00:00 2026-05-23T17:42:39+00:00

The Python documentation says that sys.path is Initialized from the environment variable PYTHONPATH ,

  • 0

The Python documentation says that sys.path is “Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.”

But what is the “installation-dependent default” exactly for Windows?

(I know this is probably dependent on how python was compiled, but if all I have is the binary, is there any way to figure out how the default sys.path is constructed?)

Clarification:
I am not asking “What is my sys.path?”. I want to know “how does Python construct sys.path?” Documentation says that sys.path is constructed with sys.path[0] being the script’s current directory, plus whatever Python finds in the PYTHONPATH environment variable, plus some installation-dependent voodoo. So what is this mysterious voodoo part?

  • 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-23T17:42:40+00:00Added an answer on May 23, 2026 at 5:42 pm

    Seems like Praveen Gollakota has good info at Troubleshooting python sys.path (repasted here:)

    • The first that is added C:\WINNT\system32\python27.zip (more details in PEP273).

    • Next ones that are added are from entries in windows registry. The entries C:\Python27\DLLs;C:\Python27\lib; C:\Python27\lib\plat-win; C:\Python27\lib\lib-tk come from HOT_KEY_LOCAL_USER/Python/PythonCore/2.7/PythonPath in the registry. More details in Python source code comments here http://svn.python.org/projects/python/trunk/PC/getpathp.c (These entries were the trickiest for me to understand until I found the link above).

    • Next, as explained in the site package documentation, sys.path is built from sys.prefix and sys.exec_prefix. On my computer both of them point to C:\Python27. And by default it searches the lib/site-packages anyway. So now the entries C:\Python27; C:\Python27\lib\site-packages are appended to the list above.

    • Next it searches each of the .pth files in alphabetical order. I have easy_install.pth, pywin32.pth and setuptools.pth in my site-packages. This is where things start getting weird. It would be straightforward if the entries in the .pth files were just directory locations. They would just get appended to the sys.path line by line. However easy_install.pth has some python code that causes the entries listed in easy_install.pth to add the packages list at the beginning of the sys.path list.

    • After this the directory entries in pywin32.pth, setuptools.pth are added at the end of the sys.path list as expected.

    Note: While the above discussion pertains to Windows, it is similar even on Mac etc. On Mac it just adds different OS defaults like darwin etc. before it starts looking at site-packages directory for .pth files.

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

Sidebar

Related Questions

I have a question about __class__ in python. The documentation says that __class__ is
The Python documentation for except says: For an except clause with an expression, that
The Python documentation says that the __init__ method of each class is responsible for
The urllib2 documentation says that timeout parameter was added in Python 2.6. Unfortunately my
In the Python documentation it says: A thread can be flagged as a daemon
The documentation of the Python readline module says Availability: Unix. However, it doesn't appear
I can't tell from the Python documentation whether the re.compile(x) function may throw an
What exactly do *args and **kwargs mean? According to the Python documentation, from what
The os.walk documentation ( http://docs.python.org/library/os.html ? highlight=os.walk#os.walk), says I can skip traversing unwanted directories
The Python documentation specifies that is is legal to omit the parentheses if a

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.