#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    2
    Rep Power
    0

    Imports in script, python env on web host


    I wrote a python script that can be run from command line but I wanted to change it so that I can run the script from php web application. I have a few questions on how to do this and did not find the answer and hope someone can answer them:

    1. The script that I wrote required some third party modules installation. How do you ensure that whey when I switch to a web script that these modules are available on my host's server? Surely, my host wouldn't just install these for me. Do I just include them in my own working directory rather than the "sites-packages" directory?

    2. Generally speaking, are there any restrictions as to the modules that I can import and use in a python web script running on a host server versus a standalone script that I run at home.

    I am concern that my python enironment that I have many not match that of the web host and would like to anticipate any changes. If anyone has any expertise in this area, I would appreciate any feedback.

    thanks,
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    1. Yes, that should work. The search path starts off by looking for the imported module in the current directory, followed by a list of other python directories. The search order is determined by the variable sys.path.
    Code:
    import sys
    print sys.path
    Of course, the modules you have in your directory may import other modules in turn, so make sure that all the required ones are present.

    2. Some restrictions may popup due to the environment that the program is running under (i.e.) Apache. The webserver may run under an unprivileged user, so you may not be able to create files or directories since you don't have the permissions to do so. The webserver may also be running chrooted, which means you may not be able to access certain command line utilities and such. All this depends on the webserver setup.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo