javier531
Posts: 11
Joined: Tue Oct 25, 2016 3:29 pm

import twython

Tue Oct 25, 2016 3:50 pm

I'm working from the command line and when I type

>>>from twython import TwythonStreamer

the prompt disappears.
After that, when I click Ctrl-C it appears again, and then, if I repeat the same command to import TwythonStreamer, it seems to work normally and the prompt appears in the next line.
When I try to import TwythonStreamer with a script, the program fails again.
Any idea about what's the problem?

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: import twython

Tue Oct 25, 2016 5:07 pm

Have you got a script called twython in your folder?

When you say the program fails, are there any error messages? If so, post them here.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

javier531
Posts: 11
Joined: Tue Oct 25, 2016 3:29 pm

Re: import twython

Tue Oct 25, 2016 5:47 pm

Thank you for your interest.
Twython is an API of Twyter that I downloaded previously. In fact, when I repeat the command, the class TwythonStreamer is properly imported.

When running it from a program, it stops and no error messages appear

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: import twython

Wed Oct 26, 2016 6:16 am

Can you post your code then please. You can hide any passwords etc.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

javier531
Posts: 11
Joined: Tue Oct 25, 2016 3:29 pm

Re: import twython

Wed Oct 26, 2016 3:33 pm

In order to isolate the problem as much as possible, I made another very simple program called test1.py:

from twython import TwythonStreamer
print "program arrived to second line"

When running it, it stops in the first line (see the screenshoot), and at this
2016-10-26-165234_1824x984_scrot.png
2016-10-26-165234_1824x984_scrot.png (61.9 KiB) Viewed 2479 times
2016-10-26-165234_1824x984_scrot.png
2016-10-26-165234_1824x984_scrot.png (61.9 KiB) Viewed 2479 times
point, when I click Ctrl-C, it appears a message that I wrote in other program several weeks ago called blinker.py that use GPIO to switch leds on/of. This message is in a except clause
After that, the program goes ahead and arrives to second line (see the screenshoot)
I can't understand why the program blinker is concerned here, but I think that this is the origin of the problem, because the first time I tried to run the script importing twython next message appeared
"Runtime warnnig.This channel is already in use, continuing anyway, Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(16, GPIO.OUT)

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: import twython

Wed Oct 26, 2016 4:33 pm

Going back to my original question, did you create a script called twython.py?

If you did, you are importing (and running) that file instead of the twython module that you want to import.

Can you print the output of

Code: Select all

ls /home/pi
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

javier531
Posts: 11
Joined: Tue Oct 25, 2016 3:29 pm

Re: import twython

Wed Oct 26, 2016 8:33 pm

No, i didn't create any script called twython.py but I can't upload the screenshot of ls command because it's bigger than the maximum allowed of 64 kb

javier531
Posts: 11
Joined: Tue Oct 25, 2016 3:29 pm

Re: import twython

Wed Oct 26, 2016 9:56 pm

Cutting the picture I got a file smaller than the allowed size
Attachments
screenshot recort.png
screenshot recort.png (24.34 KiB) Viewed 2353 times

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: import twython

Wed Oct 26, 2016 11:12 pm

OK - so that is a bit weird. If your test1.py is really just the two lines that you say it is, I don't really see why it's apparently importing blinker.py!

Can you do a python console session and do:

Code: Select all

import sys
print sys.path

import imp
imp.find_module("twython")
This should show us which paths python is searching for modules and which twython module it's importing.

Did you ever edit the twython module that you downloaded?
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

javier531
Posts: 11
Joined: Tue Oct 25, 2016 3:29 pm

Re: import twython

Thu Oct 27, 2016 3:43 pm

path_twython.png
path_twython.png (29.39 KiB) Viewed 2204 times
This is the result of the commands you said.

And obviously, I didn't edit the twython package after download it

javier531
Posts: 11
Joined: Tue Oct 25, 2016 3:29 pm

Re: import twython

Thu Oct 27, 2016 3:56 pm

I modified both files, test1.py and blinker.py by adding several print statements in order to better track the process.
Test1.py is now:

print 'This is the first line of test1.py program'
from twython import TwythonStreamer
print 'program test1.py arrived to its end'

When I run this program, this is the result:
test1_blinker.png
test1_blinker.png (17.56 KiB) Viewed 2186 times
As you can see, after the first line, when importing twython, it starts the program blinker.py (?????) and the messages that appear come from it, and after finishing blinker.py, the process continue with test1.py

I don't understand what is happening

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: import twython

Thu Oct 27, 2016 4:21 pm

How bizarre!

Try this:
Rename blinker.py to something else and delete blinker.pyc.
Run test1.py again.

Hopefully this will give you an error about not being able to find blinker and we can go from there.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

User avatar
DougieLawson
Posts: 39304
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: import twython

Thu Oct 27, 2016 6:03 pm

Have we eliminated the highly likely cause that the OP is running IDLE3 when it works and python (2) when it fails or vice versa running IDLE (2) when it works and python3 when it fails?

Remember the default command line python is a link to python2.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: import twython

Thu Oct 27, 2016 6:19 pm

Not sure that explains why the import command seems to be loading a different module (rather than being unable to find the module) but always happy to be proved wrong!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

javier531
Posts: 11
Joined: Tue Oct 25, 2016 3:29 pm

Re: import twython

Fri Oct 28, 2016 2:28 pm

Indeed. there are several python2 and python3 scripts in the same folder. Is this a problem?
Should I separate both kinds of scripts in different subfolders?
And in fact, test1.py was made in python2, and blinker.py in python3
To avoid ambiguity, I tried to execute from the line command
python2 test1.py
with the same result that was shown above (it starts running test1.py, after that it runs blinker.py, and after finishing blinker program it continues with the rest of test1.py)
Executing
python3 test1.py
it gives an error message because the print statements don't have parenthesis
I made a new script similar to test1.py but in python3 (with parenthesis in the print statements obviously), an then, when executing
python3 test3.py
next message appeared:
ImportError: No module named 'twython'

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: import twython

Fri Oct 28, 2016 2:45 pm

OK. So it sounds like twython is installed for python2.

Can you therefore please rename blinker.py (and delete blinker.pyc) as per my earlier post and re-run test1.py.

Fundamentally, importing twython should not have anything to do with blinker.py so we need to get to the root of that problem. It feels like you've edited the twython code itself but it's hard to tell.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

javier531
Posts: 11
Joined: Tue Oct 25, 2016 3:29 pm

Re: import twython

Fri Oct 28, 2016 3:09 pm

OK. I renamed blinker.py and deleted blinker.pyc and then, test1.py seems to work properly: there are no error messages, it prints the messages from the first line and the last line, and that's all.
Thank you again for your interest

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: import twython

Fri Oct 28, 2016 3:12 pm

OK. I'm glad that's helped, but that really makes no sense at all!

If test1.py was loading blinker for some reason, then removing blinker should have caused an error. I suspect there's a detail we've missed somewhere. Nevermind.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Return to “Python”