Skip to main content
update answer in response to question in comments
Source Link
samplebias
  • 38k
  • 6
  • 110
  • 104

You need to make sure your PYTHONPATH is set correctly so the command-line interpreter can find your packages, or run your test cases from within Eclipse Pydev. Update: Another option: running your tests using nose might make things a bit easier, since it can auto-discover packages and test cases.

If your project is laid out like so:

/home/user/dev/ src/pkg1/ mod1.py test/ mod1_test.py 

Use: PYTHONPATH=$HOME/dev/src python test/mod1_test.py. I'd also recommend using distribute and virtualenv to set up your project for development.

Updated in response to question in comments:

This shows how the PYTHONPATH environment variable extends Python's package sear ch path:

% PYTHONPATH=foo:bar python -c 'import sys; print sys.path[:3]' ['', '/home/user/foo', '/home/user/bar'] # exporting the variable makes it sticky for your current session. you can # add this to your shell's resource file (e.g. ~/.profile) or source # it from a textfile to save typing: % export PYTHONPATH=bar:baz % python -c 'import sys; print sys.path[:3]' ['', '/home/user/foo', '/home/user/bar'] % python -c 'import sys; print sys.path[:3]' ['', '/home/user/foo', '/home/user/bar'] 

The above should get you going in the short term. Using distribute and virtualenv have a higher one-time setup cost but you get longer-term benefits from using them. When you get a chance, read some of the many tutorials on SO for setting these up to see if they're a good fit for your project.

You need to make sure your PYTHONPATH is set correctly so the command-line interpreter can find your packages, or run your test cases from within Eclipse Pydev. Update: Another option: running your tests using nose might make things a bit easier, since it can auto-discover packages and test cases.

If your project is laid out like so:

/home/user/dev/ src/pkg1/ mod1.py test/ mod1_test.py 

Use: PYTHONPATH=$HOME/dev/src python test/mod1_test.py. I'd also recommend using distribute and virtualenv to set up your project for development.

You need to make sure your PYTHONPATH is set correctly so the command-line interpreter can find your packages, or run your test cases from within Eclipse Pydev. Update: Another option: running your tests using nose might make things a bit easier, since it can auto-discover packages and test cases.

If your project is laid out like so:

/home/user/dev/ src/pkg1/ mod1.py test/ mod1_test.py 

Use: PYTHONPATH=$HOME/dev/src python test/mod1_test.py. I'd also recommend using distribute and virtualenv to set up your project for development.

Updated in response to question in comments:

This shows how the PYTHONPATH environment variable extends Python's package sear ch path:

% PYTHONPATH=foo:bar python -c 'import sys; print sys.path[:3]' ['', '/home/user/foo', '/home/user/bar'] # exporting the variable makes it sticky for your current session. you can # add this to your shell's resource file (e.g. ~/.profile) or source # it from a textfile to save typing: % export PYTHONPATH=bar:baz % python -c 'import sys; print sys.path[:3]' ['', '/home/user/foo', '/home/user/bar'] % python -c 'import sys; print sys.path[:3]' ['', '/home/user/foo', '/home/user/bar'] 

The above should get you going in the short term. Using distribute and virtualenv have a higher one-time setup cost but you get longer-term benefits from using them. When you get a chance, read some of the many tutorials on SO for setting these up to see if they're a good fit for your project.

added note about using nose
Source Link
samplebias
  • 38k
  • 6
  • 110
  • 104

You need to make sure your PYTHONPATH is set correctly so the command-line interpreter can find your packages, or run your test cases from within Eclipse Pydev. Update: Another option: running your tests using nose might make things a bit easier, since it can auto-discover packages and test cases.

If your project is laid out like so:

/home/user/dev/ src/pkg1/ mod1.py test/ mod1_test.py 

Use: PYTHONPATH=$HOME/dev/src python test/mod1_test.py. I'd also recommend using distribute and virtualenv to set up your project for development.

You need to make sure your PYTHONPATH is set correctly so the command-line interpreter can find your packages, or run your test cases from within Eclipse Pydev.

If your project is laid out like so:

/home/user/dev/ src/pkg1/ mod1.py test/ mod1_test.py 

Use: PYTHONPATH=$HOME/dev/src python test/mod1_test.py. I'd also recommend using distribute and virtualenv to set up your project for development.

You need to make sure your PYTHONPATH is set correctly so the command-line interpreter can find your packages, or run your test cases from within Eclipse Pydev. Update: Another option: running your tests using nose might make things a bit easier, since it can auto-discover packages and test cases.

If your project is laid out like so:

/home/user/dev/ src/pkg1/ mod1.py test/ mod1_test.py 

Use: PYTHONPATH=$HOME/dev/src python test/mod1_test.py. I'd also recommend using distribute and virtualenv to set up your project for development.

Source Link
samplebias
  • 38k
  • 6
  • 110
  • 104

You need to make sure your PYTHONPATH is set correctly so the command-line interpreter can find your packages, or run your test cases from within Eclipse Pydev.

If your project is laid out like so:

/home/user/dev/ src/pkg1/ mod1.py test/ mod1_test.py 

Use: PYTHONPATH=$HOME/dev/src python test/mod1_test.py. I'd also recommend using distribute and virtualenv to set up your project for development.