Python cannot see installed module `news`

梦想的初衷 提交于 2019-12-25 09:35:34

问题


Python declares that the news module is not installed:

$ python -c "import news"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named news

Even though:

$ pip show news
Name: news
Version: 1.0
Summary: my first python module
Home-page: UNKNOWN
Author: sang
Author-email: 1975001828@qq.com
License: UNKNOWN
Location: /usr/lib/python2.7/site-packages
Requires:

$ python -V
Python 2.7.10

$ echo $PYTHONPATH
:/usr/lib/python2.7/site-packages

$ python -c "import sys; print sys.path"
['', '/usr/lib/python2.7/site-packages/pydns-2.3.6-py2.7.egg', '/usr/lib/python2.7/site-packages/xmltodict-0.10.2-py2.7.egg', '/usr/lib/python2.7/site-packages/spambayes-1.1b1-py2.7.egg', '/usr/lib/python2.7/site-packages/pydns-2.3.6-py2.7.egg', '/usr/lib/python2.7/site-packages/lockfile-0.11.0-py2.7.egg', '/usr/lib/python2.7/site-packages/FinancialFundamentals-0.2.3-py2.7.egg', '/usr/lib/python2.7/site-packages/vector_cache-0.1.0-py2.7.egg', '/usr/lib/python2.7/site-packages/python_dateutil-1.5-py2.7.egg', '/usr/lib/python2.7/site-packages/blist-1.3.6-py2.7-cygwin-2.5.2-i686.egg', '/usr/lib/python2.7/site-packages/xmltodict-0.10.2-py2.7.egg', '/usr/lib/python2.7/site-packages/buildozer-0.33.dev0-py2.7.egg', '/home/Administrator/python/scrapping/guru_steve_avon', '/usr/lib/python2.7/site-packages', '/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-cygwin', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/Administrator/.local/lib/python2.7/site-packages', '/usr/lib/python2.7/site-packages/PIL', '/usr/lib/python2.7/site-packages/gst-0.10', '/usr/lib/python2.7/site-packages/gtk-2.0']

Any suggestions what can be done to get news to be recognized?


Edit 1, in reply to @JacobIRR:

news was installed - without complaint - with pip (see below), but there does not seem to be a news subdirectory in site-packages.

$ ls -lsad  /usr/lib/python2.7/site-packages/n*
 0 drwxr-xr-x+ 1 Administrator None   0 Jun  4  2015 /usr/lib/python2.7/site-packages/ndg
 1 -rw-r--r--  1 Administrator None 297 Jun  4  2015 /usr/lib/python2.7/site-packages/ndg_httpsclient-0.4.0-py2.7-nspkg.pth
 4 drwxr-xr-x+ 1 Administrator None   0 Jun  4  2015 /usr/lib/python2.7/site-packages/ndg_httpsclient-0.4.0-py2.7.egg-info
 4 drwxr-xr-x+ 1 Administrator None   0 Feb 25  2016 /usr/lib/python2.7/site-packages/netsnmp
 4 drwxr-xr-x+ 1 Administrator None   0 Feb 25  2016 /usr/lib/python2.7/site-packages/netsnmp_python-1.0a1-py2.7.egg-info
 4 drwxr-xr-x+ 1 Administrator None   0 Apr 26  2016 /usr/lib/python2.7/site-packages/networkx
 4 drwxr-xr-x+ 1 Administrator None   0 Apr 26  2016 /usr/lib/python2.7/site-packages/networkx-1.11.dist-info
 4 drwxr-xr-x+ 1 Administrator None   0 Apr  8 21:28 /usr/lib/python2.7/site-packages/news-1.0.dist-info
 1 -rw-r--r--  1 Administrator None 154 Apr  8 21:28 /usr/lib/python2.7/site-packages/news_module.py
 1 -rw-r--r--  1 Administrator None 457 Apr  8 21:28 /usr/lib/python2.7/site-packages/news_module.pyc
12 drwxr-xr-x+ 1 Administrator None   0 Sep 27  2015 /usr/lib/python2.7/site-packages/nltk
 4 drwxr-xr-x+ 1 Administrator None   0 Sep 27  2015 /usr/lib/python2.7/site-packages/nltk-3.0.5-py2.7.egg-info
 0 drwxr-xr-x+ 1 Administrator None   0 Apr 13  2015 /usr/lib/python2.7/site-packages/numba
 0 drwxr-xr-x+ 1 Administrator None   0 Apr 13  2015 /usr/lib/python2.7/site-packages/numba-0.18.2-py2.7.egg-info
 0 drwxr-xr-x+ 1 Administrator None   0 Feb 25  2016 /usr/lib/python2.7/site-packages/numpy
 0 drwxr-xr-x+ 1 Administrator None   0 Apr 26  2016 /usr/lib/python2.7/site-packages/numpy-1.11.0.dist-info
 0 drwxr-xr-x+ 1 Administrator None   0 Apr  9  2015 /usr/lib/python2.7/site-packages/numpy-1.9.2-py2.7.egg-infoold-1
 0 drwxr-xr-x+ 1 Administrator None   0 Jun 18  2015 /usr/lib/python2.7/site-packages/numpy-1.9.2-py2.7.egg-infoold-2

$ pip uninstall news
Uninstalling news-1.0:
  /usr/lib/python2.7/site-packages/news-1.0.dist-info/DESCRIPTION.rst
  /usr/lib/python2.7/site-packages/news-1.0.dist-info/INSTALLER
  /usr/lib/python2.7/site-packages/news-1.0.dist-info/METADATA
  /usr/lib/python2.7/site-packages/news-1.0.dist-info/RECORD
  /usr/lib/python2.7/site-packages/news-1.0.dist-info/WHEEL
  /usr/lib/python2.7/site-packages/news-1.0.dist-info/metadata.json
  /usr/lib/python2.7/site-packages/news-1.0.dist-info/top_level.txt
  /usr/lib/python2.7/site-packages/news_module.py
  /usr/lib/python2.7/site-packages/news_module.pyc
Proceed (y/n)? y
  Successfully uninstalled news-1.0

$ pip install news
Collecting news
Installing collected packages: news
Successfully installed news-1.0

回答1:


Well, I downloaded the module from pypi to see what is inside it. The news-1.0.zip has only one file called news_module.py and has one method read_news in it.

So, you should try

$ python -c "import news_module"

Q: Are you looking for newspaper module instead?



来源:https://stackoverflow.com/questions/43299096/python-cannot-see-installed-module-news

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!