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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:57:45+00:00 2026-05-29T10:57:45+00:00

I am looking how to import modules by setting the pythonpath. To check the

  • 0

I am looking how to import modules by setting the pythonpath.
To check the paths python is looking at:

import sys
print "modules will be searched in the following paths:"
for path in sys.path:
    print path
print "python version: " + sys.version

I added some extra paths in PYTHONPATH environment variable (windows gui), but when executing the code above as a cgi file in apache (in the browser), it does not show my added paths…(and indeed, it will not load modules from the missing paths)
When I execute the code with python locally, all paths are shown (so that’s ok).

#!C:\tools\programming\Python27\python.exe
import cgi
import cgitb
cgitb.enable()
print "Content-type: text/html" 
print
import sys

#import timeOperations

for path in sys.path:
    print path + "<br>"

print "python version: " + sys.version
print "<html>"
print "<center>Lode doet het weer!</center>"
print "</html>"

I did a computer reboot, no succes. There is also only one python version installed.

Why gives the PYTHONPATH a different value? I don’t know.
Any help is appreciated!

Lode

  • 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-29T10:57:45+00:00Added an answer on May 29, 2026 at 10:57 am

    I personally don’t like adding things to the PYTHONPATH through an environment variable for this very reason. I suspect that the reason is that your PYTHONPATH environment variable has a different scope than the one Apache is using. For example, your variable might be local to your user, while Apache runs with just the system environment variables.

    I find it more reliable to bypass environment variables completely by adding a “.pth” file to your site-packages directory. Execute the following code from the python interpreter:

    import distutils.sysconfig
    print distutils.sysconfig.get_python_lib()
    

    This will print the location of your “site-packages” directory. Visit that directory (from the command-line or Windows Explorer) and create a file in it called “MyPythonPath.pth” (or something else with the extension “.pth”). In it, include each value you wanted to add to your PYTHONPATH on separate lines:

    C:\Path\to\first\directory
    C:\Path\to\second\directory
    

    Next time you run Python, these folders will be added to your path, no matter where you run it—as long as you are always using the same Python interpreter.

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

Sidebar

Related Questions

Possible Duplicate: Dynamic module import in Python I have a list of modules, like
Looking for the correct way and control to import and export of out of
I'm looking for a clean way to import one git repository from another, where
I am looking to build a multi-threaded text import facility (generally CSV into SQL
Looking for C# class which wraps calls to do the following: read and write
Looking for a Linux application (or Firefox extension) that will allow me to scrape
I'm looking into organizing my modules and classes. All the time I collect my
I am relatively new to Python. I am looking to create a settings module
I was trying out one of the Python standard library modules, let's call it
Good morning, I am currently writing a python library. At the moment, modules and

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.