Tyler Burleigh
Tyler Burleigh

Reputation: 537

Failed to load application: No module named

I'm having difficulty launching a twisted python script outside its working directory. When I try, I receive the following error:

exceptions.ImportError: No module named mining

My understanding is that if I add the module's path to sys.path, then it should be able to find it. For example, I have added:

sys.path.append("/root/stratum-mining/mining")

I have also tried changing the working directory of the script using

os.chdir('/root/stratum-mining')

I've verified that the module's path is in sys.path, but as soon as it gets to "import mining" it fails.

Am I missing something?

Upvotes: 0

Views: 2446

Answers (1)

Aya
Aya

Reputation: 41980

For Python packages, you have to add the directory containing the package directory to PYTHONPATH or sys.path, not the package directory itself, so changing...

sys.path.append("/root/stratum-mining/mining")

...to...

sys.path.append("/root/stratum-mining")

...should allow you to import mining as long as /root/stratum-mining/mining is accessible, and contains a file named __init__.py.

Upvotes: 1

Related Questions