3

I just wrote a python script to fix some database issues and it uses the psycopg2 module. For some reason the person that needs to run it (on the server) is claiming that they can't install psycopg2 on their server machine... is there a way that I can package that module within my script such that they don't have to have psycopg2 installed? Something similar to adding a lib folder to the classpath in Java?

Thx in advance, Andre

5
  • If the whole module's written in Python and has no extra dependencies you should just be able to put it in the same folder. Commented Jan 31, 2011 at 20:18
  • What OS is the server running? Is it the same as the OS on your machine? Commented Jan 31, 2011 at 22:11
  • The server is running CentOS, I'm on a mac. Commented Feb 1, 2011 at 6:51
  • @piro lol, that's what we ended up doing :P Commented Feb 23, 2011 at 0:09
  • great! If you contribute a patch I'll be able to use it in many of my projects! :D Commented Feb 24, 2011 at 13:29

2 Answers 2

1

Make a directory, put your script into it.

cd into that directory, then run:

$ easy_install -Z --prefix . psycopg2

That should result in a copy of the python module in the same directory.

Zip it all up and send the whole thing off.

Sign up to request clarification or add additional context in comments.

Comments

0

As to be unable to install psycopg2, I sure it relates to security policies about who can have root access on database servers. If you can't find someone with the necessary permissions, there are two methods to skin this particular cat:

1) You could build an exe using py2exe, that way you know that all of the dependencies for your scripts are there and available. Also this will allow to you escape dealing with any python incompatibilities. You made no mention of your python version (2.5, 2.6, 2.7, 3.1?) nor the version on the server.

2) Or you could place the psycopg2 module into its own directory (c:\mypymods) and add the path to sys.path before importing.

import sys
sys.path = sys.path.append("c:/mypymods")
import psycopg2
....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.