problem with import .py

Asked by harry

Hi I'm using

Linux debian jessie
sikulix 1.1.0 or 1.1.1(I installed it but when I run 'java -jar sikulix.jar', SikulixIDE 1.1.0 is open)
jython 2.7.0

When I use Sikuli X 1.0, I can run sikuli in command line by 'sikuli-ide -r xxx.sikuli' with other python file like 'send_email.py' which sends email by just put this 'import send_email' in my xxx.sikuli directory.

Now, I need to use sikulix 1.1.0 to use jython 2.7.0 properly(I need to make a post request to an api to upload a file) in my Linux machine. I can run the script with the Sikulix 1.1.0 IDE, but I got error message

'[error] ImportError ( No module named formdata )'

formdata is from http://code.activestate.com/recipes/578668-encode-multipart-form-data-for-uploading-files-via/

and this is my code

=================================================================
import urllib2
import formdata

client_id = "1234"

url = 'http://localhost:9292'
file = '/home/txt.txt'
fields = {'name': 'BOB SMITH'}
files = {'file': {'filename': file, 'content': 'Data here'}}
data, headers = formdata.encode_multipart(fields, files)
request = urllib2.Request('http://localhost:9292/attachments?client_id='+client_id, data=data, headers=headers)
f = urllib2.urlopen(request)
print f.read()
=================================================================

This is the command that I run in the command line

java -jar sikulix.jar -i -r ../sikuli/test.sikuli

[info] runcmd: lsb_release -i -r -s
[error] script [ /home/sikuli/testtest.sikuli ] stopped with error in line 2
[error] ImportError ( No module named formdata )

I put the formdata.py in the test.sikuli which is same directory as test.py.

I wonder why it is not work in command line with Sikulix 1.1.0 because it works in Sikulix 1.1.0 IDE and previous version.

Do I need to get 1.1.1 ?
I got 1.1.1 from http://nightly.sikuli.de/ and when I install it, it says it installs 1.1.1 but when I run the .jar file, it opens 1.1.0 IDE.

Thank you for your help in advance.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

- jar 1.1.1 starts as SikuliX IDE 1.1.0
check again carefully: you seem to have some mix-up of the different versions. Take care, that nothing in your environment points to 1.1.0 stuff.
Recommendation: put 1.1.0 aside completely and make a fresh setup for 1.1.1

- .py modules in a .sikuli
... is not recommended
Python feature modules like send_email and formdata should reside in central folders.
About the options with 1.1.1 see:
http://sikulix-2014.readthedocs.io/en/latest/scenarios.html#access-python-packages-from-sikulix-scripts-run-by-sikulix-gui-or-commandline

to check your sys.path put a
for e in sys.path: print e

at the very beginning of your main script run by SikuliX

Can you help with this problem?

Provide an answer of your own, or ask harry for more information if necessary.

To post a message you must log in.