Take the 2-minute tour ×

I'm in the process of redesigning/refactoring my Python quantum chemistry package (pyquante). One of the things I don't like about the existing release is that I have to install the package to run the test suite. That is, the test suite has statements like from PyQuante import SCF, and, of course, this PyQuante could refer to the installed version or a local version.

I know about virtualenv, and realize this is an option for me. But I was wondering whether anything else might be appropriate. In the past I've hacked sys.path for things like this, and have been told by better Python programmers that I shouldn't ever to this.

Does anyone have any suggestions for how I can do this? The point is that I want to test the current version of the code without installing it.

Thanks in advance for anyone who can see through my babbling and offer suggestions!

share|improve this question
May I ask an explanation, why you shouldn't "hack" sys.path? –  khachik Apr 15 '11 at 13:58
Afaik, with setupstools you can use develop instead of install to install a linked version which points to your development project. Thus no need to ever reinstall it. –  ZeissS Apr 15 '11 at 14:03
@khackik it can lead to things not being present, and cause things to break. it's mainly because people tend to forget what they did to sys.path and continue business as usual. if your careful, it shouldn't be a problem. –  myusuf3 Apr 15 '11 at 14:33
add comment

3 Answers

up vote 6 down vote accepted

Create a proper package for your stuff and use

python setup.py develop

to make it a proper dev-package.

share|improve this answer
Thanks! I didn't know about this option, and it seems exactly what I was looking for. –  Rick Apr 15 '11 at 14:44
add comment

Altering sys.path much in production environment may be unwise. Altering it for testing is usually OK.

If you don't want to tinker with the variable from sys, use an environment variable named PYTHONPATH, it's a clean and documented way.

share|improve this answer
At program startup by default, the first item of sys.path, path[0], is the directory containing the script that was used to invoke the Python interpreter. This means that all you need to do is just put your test suite in the same directory that the module it tests is in and importing it will work. –  martineau Apr 15 '11 at 14:45
add comment

I would honestly insist on using virtualenv, its designed for this exact reason in mind. very small overhead, and if you ever mess up just delete directory. I am sure as you grow, things won't be as simple as they are now for your current situation. Take it as an opportunity to learn.

share|improve this answer
Yes I agree with this. Here's an introduction : stackoverflow.com/questions/13490351/…. And here the official web site : virtualenv.org/en/latest –  Gauthier Boaglio Jun 10 '13 at 10:24
add comment

Your Answer


