当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Cannot import Twython

问题描述:

I installed Twython 1.2 using the Windows installer at this link: https://pypi.python.org/pypi/twython/1.2. The installer seems to run fine.

I get the error "ImportError: cannot import name Twython" when I try to do:

from twython import Twython

from twython import TwythonStreamer

Does anybody know why I cannot import twython?

网友答案:

Mmmm, Twython's current version is 3.x.x, not 1.2. I think that 1.2 installer is from yeaaars ago when I first started the project - the Twython API and structure has changed a ton since then.

网友答案:

Usually you need to set the environment variable PYTHONPATH to point to the path containing the file twython.py. I'm not sure exactly where Twython installs itself, but presumably it told you during the installation. If not, search for the file twython.py, and the directory it's in is the one you want. I'm not sure how you're running your Python script that imports Twython. If it's from the DOS prompt, try something like

set PYTHONPATH="c:\Program Files\Twython1.2\SOMEDIR"

substituting the actual directory containing twython.py (which might not be in c:\Program Files).

If you're running your script graphically, then if you're running inside some sort of Python IDE, it might have a way of setting PYTHONPATH in its Preferences. Otherwise, you need to go to the Control Panel and find the place where you can set environment variables. It's been awhile since I've used Windows and things have changed recently but it might be under Startup or similar, then under Advanced... or similar.

分享给朋友:
您可能感兴趣的文章:
随机阅读: