I'm having trouble getting sikuli+python unit testing to work, and would be glad for some assistance.
I searched the internet far and wide, but haven't anything that worked. My python knowledge is very limited, and I guess that doesn't help...
I'm using win7 32,
sikuli 1.0 rc3 (r905),
python 2.7.3
I'm trying to start running sikuli unit tests through python (not with command line, just as a python script to run with the python gui). I've followed, among others, the instructions shown here: http://sikuli.org/docx/globals.html
and here: https://answers.launchpad.net/sikuli/+faq/1804
my sikuli script (name: slidelyChromeUnitTest2.sikuli) starts like this (the rest doesn't matter becuase it gets stuck on the very first line):
from sikuli import *
import unittest
and my python script (name: SikuliTestRunner.py) looks like this:
import sys
mySikuliPath = "D:\\Program Files\\Sikuli X\\slidelyChromeUnitTest2.sikuli"
if not mySikuliPath in sys.path: sys.path.append(mySikuliPath)
import slidelyChromeUnitTest2
And what I get when I run the python script is this:
Traceback (most recent call last): File
"D:\Python27\SikuliTestRunner.py", line 6, in
import slidelyChromeUnitTest2 File "D:\Program Files\Sikuli X\slidelyChromeUnitTest2.sikuli\slidelyChromeUnitTest2.py", line 1, in
from sikuli import * ImportError: No module named sikuli
And I can't get past that error...
What am I doing wrong?
Thank you,
Ilan
It's Jython you can't.
http://doc.sikuli.org/devs/system-design.html
edit: updated the link, removed a dead post reference.
Related
When I execute a Python script I receive:
Traceback (most recent call last):
File "/Users/.../Documents/development/python/migrate_upper.py", line 3, in <module>
import mysql.connector
ImportError: No module named connector
I am executing like that:
$ python migrate_upper.py
It worked 1 month ago, I haven't worked with Python since then. I spent 2 hours trying to understand what is wrong but I got lost with PYTHONPATH, pip and other hints.
However when I send the script to Python shell:
$ python < migrate_upper.py
everything works. I think that this is not the proper way to execute python scripts. How can I get the script working without the Python shell?
I resolved it with the help of Ethan's comment.
I had a folder mysql beneath ../development/python. I can't remember why I put it there. I guess python tried to import that folder instead of ../site-packages/mysql.
I'm seeing weird behavior that I don't understand, so I'm turning to the experts here on SO for help. I have looked at similar questions, without finding anything that looked helpful.
I'm writing a program that imports two custom modules.
If I run the main program using the cli "./ld_config_automation.py" I get the following error:
laptop$ ./ld_config_automation.py
Traceback (most recent call last):
File "./ld_config_automation.py", line 34, in <module>
from modules.networkcomponent import NetworkComponent
File "/path/to/pprograms/ssh_telnet_automation/modules/networkcomponent.py", line 7, in <module>
import pexpect
ImportError: No module named pexpect
However, if I run the main program using the cli "python ld_config_automation.py" everything works fine and the program runs.
My main program uses the following import statements.
import sys
import getopt
from modules.networkcomponent import NetworkComponent
from modules.recordclass import Record
The module I'm having trouble with "NetworkComponent" uses the following import statements:
import re
import pexpect
Also, if I remove import pexpect from the NetworkComponent module it works as expected without python in front (up to when it has to use pexpect. of course). So it doesn't seem to be a problem with importing modules, as re works ok, just not pexpect.
I'm developing this on mac os X but will implement on CentOS.
The first two lines of the program are:
from i2clibraries import i2c_lcd
from ABElectronics_ADCPi import ADCPi
No matter what line is first the Pi returns an error when I attempt to run it under Python or Python 3. All the libraries are possessed and registered. Using the shell commands the checks saying the exports worked correctly all show up correctly. However, whatever line is line 1 will return a missing module error and the i2clibraries will always return a missing module error. By keeping that as the first line I get the least errors in running, but the program still returns this:
pi#raspberrypi ~ $ sudo python file.py
Traceback (most recent call last):
File "file.py", line 1, in <module>
from i2clibraries import i2c_lcd
File "/home/pi/i2clibraries/i2c_lcd.py", line 1, in <module>
from i2clibraries import i2c
File "/home/pi/i2clibraries/i2c.py", line 1, in <module>
from quick2wire.i2c import I2CMaster, writing_bytes, reading
ImportError: No module named quick2wire.i2c
Given the error, what possible solutions are there to stop the first line from being unable to find its module?
Problem
The error message is telling you that when you try to import the i2clibraries module, the imports that it requires (dependencies) cannot be found when it is itself is being imported. This is specifically in the first line of i2c.py file - where the line
from quick2wire.i2c import I2CMaster, writing_bytes, reading
is failing.
The problem is almost certainly that your modules are not on the Python module search path. Further info on this is given at the end of this answer should you need it.
Solution
There are a number of ways to resolve this. The one recommended by the developers of the module is
To use the library without installation, add the full path of the
source tree to the PYTHONPATH environment variable. For example:
export QUICK2WIRE_API_HOME=[the directory cloned from Git or unpacked from the source archive]
export PYTHONPATH=$PYTHONPATH:$QUICK2WIRE_API_HOME
So, you need to know where your quick2wire libraries are installed - from your error message, I would hazard a guess that they are in /home/pi/i2clibraries/, so $QUICK2WIRE_API_HOME=/home/pi/i2clibraries/ should be your first line of the above pair.
Further info
You can read more generally about how to install modules on Python 2.x on the Python website. You can look at what paths make up the module search path by going to an interactive Python prompt (i.e. typing python) and then doing.
>>> import sys
>>> sys.path
This will output a list containing strings representing all the paths that will be searched for modules.
Somehow my python is broken and emits the error:
jseidel#EDP15:/etc/default$ python -c 'import random'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.6/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
This is NOT the virtualenv error that is so commonly documented here and elsewhere: I don't use python directly, I have never setup a virtualenv explicitly, and there is no virtualenv directory or python script that I can find anywhere on my system.
I'm running Kubuntu 10.04 and until just recently my KPackageKit worked just fine and handled updates with no problem. Now it shows nothing... maybe because of this python error, maybe because of something else.
How do I go about finding the error and fixing python?
As suggested by #Armin Rigo, this worked for me:
1) Add a print 42 at the end of the /usr/lib/python2.6/os.py file.
2) If you see "42", then that is the correct os.py file and the urandom module is not include. Add the statement to include urandom (you can find a sample from another os.py file). This was what worked for me.
3) If you don't see "42", then that's not the os.py file that you're using. Find the random.py file that is crashing and insert import os; print os.__file__ to get more information about the failure.
File "/usr/local/lib/python2.5/site-packages/libxml2.py", line 1, in <module>
import libxml2mod
ImportError: /usr/local/lib/python2.5/site-packages/libxml2mod.so:
undefined symbol:xmlTextReaderSetup
>>> import libxml2mod
>>> import libxml2
>>>
on Python Prompt it works fine !!
can anyone has idea why my program is not working from .py file as import is working perfect from python prompt.
I can only suggest that your paths are different for some reason. Either that, or you are not using the same python interpreter in both cases.
I have experienced this when I happen to have a couple of interpreters, and the wrong one is either default, or specified in the #! section of the script.