10

For this file layout:

devel/
 pkg/
 __init__.py
 moduleA.py
 moduleB.py
 test/
 __init__.py
 test_A.py
 test_B.py

If I am in the directory which contains the pkg (devel), I can run:

python -m pkg.test.test_A

But what if I want to run the same but with absobule path? I tried:

python -m /Users/me/docs/devel/pkg.test.test_A

Assuming I don't want to do the following and change the directory in my bash script:

cd /Users/me/docs/devel/
python -m pkg.test.test_A

Is there any direct way from python command?

asked Apr 16, 2014 at 17:16
0

1 Answer 1

13

Add /Users/me/docs/devel to your module search path:

PYTHONPATH=/Users/me/docs/devel python -m pkg.test.test_A
answered Apr 16, 2014 at 17:24
Sign up to request clarification or add additional context in comments.

3 Comments

So that's the only way? Because you know, you can run any sole file with the absolute path python /path/to/file/file.py. Thanks
Either way should work, although note that you can't mix file paths and dotted module names; you would need python /Users/me/docs/devel/pkg/test/testA.py.
Yes I tried that unsuccessfully on my first attempt. I have relative imports (from .. import) inside the testA so I can only run it as a module. Pythonpath should be fine. Thank you

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.