0

How does Python (or MonkeyRunner) locate imported modules?

I previously asked about an error I get when running a monkeyrunner script from Git Bash. I still haven't resolved the issue and decided to try running it from the Windows 7 command line. I cd to the directory containing my .py files and run

> monkeyrunner screenshots.py
Can't open specified script file
Usage: monkeyrunner [options] SCRIPT_FILE

-s      MonkeyServer IP Address.
-p      MonkeyServer TCP Port.
-v      MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF)

screenshots.py is indeed in the current directory. Why can't monkeyrunner find it? What do I need to do to fix this to run on Windows 7?

Community
  • 1
  • 1
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Did you ever get an answer? I'm having the same problem. – Andi Jay Nov 27 '13 at 19:03
  • @AndiJay It appears to be a bug in how Monkey Runner parses the python search path (see the "update" in the linked question). However, I have not found a solution to this problem on Windows. I primarily use Linux now which doesn't have this same issue. – Code-Apprentice Nov 27 '13 at 21:32
  • Possible duplicate of [How does Python (or MonkeyRunner) locate imported modules?](http://stackoverflow.com/questions/18115318/how-does-python-or-monkeyrunner-locate-imported-modules) – Code-Apprentice Oct 04 '16 at 17:44

2 Answers2

0

did you try giving full path to your screenshots.py.

monkeyrunner C:\folder_location_to_your_file\scrrenshots.py

Rilwan
  • 2,251
  • 2
  • 19
  • 28
  • Thanks for the suguggestion. I'll give that a shot to see what happens. (Even if it loads `screenshots.py`, my guess is that it will still have issues loading my `util` module that it imports. One step at a time, though.) – Code-Apprentice Aug 26 '13 at 23:05
  • from windows command-line you should be able to import custom modules if your folder structure is correct. I am sorry,i haven't tried from Git bash.Anyway keep posted, i can also learn. :-) – Rilwan Aug 27 '13 at 05:57
0

There is an easier way to call monkeyrunner script if the cmd is in the directory that contains your script:

monkeyrunner "%cd%\your_script.py"

Make sure you put the "" marks.

Vikash Pandey
  • 5,407
  • 6
  • 41
  • 42
Jelena
  • 1
  • 1
  • What the `cd` variable? – Code-Apprentice Sep 22 '16 at 15:24
  • The %cd% referes to the current directory of the cmd, e.g. if your script is in C:\scripts folder and your cmd is in that directory, monkeyrunner "%cd%\script.py" would be the same as monkeyrunner "C:\scripts\script.py". – Jelena Oct 04 '16 at 14:40