Diolor
Diolor

Reputation: 13450

Run Python module with absolute path

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?

Upvotes: 10

Views: 8773

Answers (1)

chepner
chepner

Reputation: 530990

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

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

Upvotes: 13

Related Questions