Forum Archive

[Solved]ImportError when importing Images, Twitter and more

uj_jonas

I installed @bear's python-twitter https://github.com/bear/python-twitter with stash like this pip install python-twitter

I should of course have just looked for a Twitter module in the pythonista documentation, which I did after installing python-twitter and realized I should just use that.

There was just one problem:
import twitter

raised the following error:

ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.

This doesn't just happen when I import twitter, but also with Images, when I run my script the uploads pictures to Imgur and when I open the pythonista 3 widget from the share menu.

ccc

The problem that you have is that Pythonista already comes with a module built in that you access with import twitter and then you installed a second, different module that you also access with import twitter. You now have a namespace collision and those two modules are colliding in ways that might be difficult to disentangle.

uj_jonas

Yes, I thought it was something like that :/

uj_jonas

But why does this affect other modules?

uj_jonas

@ccc and now it raised a new error
module "copyreq" has no attribute "pickle"

Damn I wish there was a undo button in stash

JonB

Anything you installed in stash can be found by going to

cd ~/Documents/site-packages

then, if you find a folder you don't want, simply delete it

rm -rf twitter

if you have already imported the module, force quit pythonista, then restart, and you should be good to go.

uj_jonas

@JonB didn't quite work.
I did remove the twitter folder, but now it's just back to the first error.
And I'm still wondering why this affects other modules. The ImportError says I'm either running Python-future from the src folder or it's corrupted, it think it's corrupted

JonB

So, to be clear:
if you type
import twitter in the console, running the 3.5 interpreter, you get that error?

What about from the 2.7 interpreter.

Make sure you don't have another twitter.py somewhere...

import twitter
twitter.file
'/var/mobile/Containers/Bundle/Application/4F1ECB6D-347F-4B3F-870B-9156A42DBDB0/Pythonista3.app/Frameworks/PythonistaKit3.framework/pylib/site-packages/twitter.py'

JonB

oh, the problem is that python twitter also installed future, since stash runs py2.7.

Delete future from site packages as well

uj_jonas

@JonB future is now gone.

All I'm doing is
import twitter
It doesn't work in 3.5
It works in 2.7

From the console(2.7):

>>> import twitter
>>> twitter.__file__
'/var/containers/Bundle/Application/05B93F09-B103-44A6-9622-55237A53AC5E/Pythonista3.app/Frameworks/PythonistaKit.framework/pylib/site-packages/twitter.py'
uj_jonas

@JonB is everything in site-packages what stash has installed?
If so, wouldn't trashing it all fix the problem?

lukaskollmer

@uj_jonas yes, stash saves packages installed via pip to the site-packages folder, but I wouldn't delete everything. Just look if there is a folder named Twitter in site-packages And try renaming/deleting that one

uj_jonas

@lukaskollmer I got it all working again, except imgurpython.
I removed it from site-packages and tried to reinstall it with pip, but it wouldn't let me.