我在使用我的代码找到我的beautifulsoup4模块时遇到了一些麻烦。 列出我安装的模块时,python给出了我在下面提供的列表(没有提到beatifulsoup4或bs4)
但是,当我运行模块的pip安装时,我得到了输出,可以在下面看到
如果有人能够解释这种差异和/或提供我的文件所需的代码来找到这个很棒的模块。
(如果有用:我的代码在Home / username / Desktop / mycode中,我的模块安装在Home / username / Desktop / python2.7 / dist-packages / bs4
pip install beautifulsoup4
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /usr/lib/python2.7/dist-packages
Cleaning up...
模块:
>>> help('modules')
Please wait a moment while I gather a list of all available modules...
BaseHTTPServer asynchat imaplib sha
Bastion asyncore imghdr shelve
CDROM atexit imp shlex
CGIHTTPServer audiodev importlib shutil
Canvas audioop imputil signal
ConfigParser base64 inspect site
Cookie bdb io smtpd
DLFCN binascii itertools smtplib
Dialog binhex json sndhdr
DocXMLRPCServer bisect keyword socket
FileDialog bsddb lib2to3 spwd
FixTk bz2 linecache sqlite3
HTMLParser cPickle linuxaudiodev sre
IN cProfile locale sre_compile
MimeWriter cStringIO logging sre_constants
Queue calendar macpath sre_parse
ScrolledText cgi macurl2path ssl
SimpleDialog cgitb mailbox stat
SimpleHTTPServer chunk mailcap statvfs
SimpleXMLRPCServer cmath markupbase string
SocketServer cmd marshal stringold
StringIO code math stringprep
TYPES codecs md5 strop
Tix codeop mhlib struct
Tkconstants collections mimetools subprocess
Tkdnd colorsys mimetypes sunau
Tkinter commands mimify sunaudio
UserDict compileall mmap symbol
UserList compiler modulefinder symtable
UserString contextlib multifile sys
_LWPCookieJar cookielib multiprocessing sysconfig
_MozillaCookieJar copy mutex syslog
__builtin__ copy_reg netrc tabnanny
__future__ crypt new tarfile
_abcoll csv nis telnetlib
_ast ctypes nntplib tempfile
_bisect curses ntpath termios
_codecs datetime nturl2path test
_codecs_cn dbhash numbers textwrap
_codecs_hk dbm opcode this
_codecs_iso2022 decimal operator thread
_codecs_jp difflib optparse threading
_codecs_kr dircache os time
_codecs_tw dis os2emxpath timeit
_collections distutils ossaudiodev tkColorChooser
_csv dl parser tkCommonDialog
_ctypes doctest pdb tkFileDialog
_ctypes_test dumbdbm pickle tkFont
_elementtree dummy_thread pickletools tkMessageBox
_functools dummy_threading pipes tkSimpleDialog
_hashlib email pkgutil toaiff
_heapq encodings platform token
_hotshot errno plistlib tokenize
_io exceptions popen2 trace
_json fcntl poplib traceback
_locale filecmp posix ttk
_lsprof fileinput posixfile tty
_multibytecodec fnmatch posixpath turtle
_multiprocessing formatter pprint types
_osx_support fpformat profile unicodedata
_pyio fractions pstats unittest
_random ftplib pty urllib
_socket functools pwd urllib2
_sqlite3 future_builtins py_compile urlparse
_sre gc pyclbr user
_ssl gdbm pydoc uu
_strptime genericpath pydoc_data uuid
_struct getopt pyexpat warnings
_symtable getpass quopri wave
_sysconfigdata gettext random weakref
_testcapi glob re webbrowser
_threading_local grp readline whichdb
_tkinter gzip repr wsgiref
_warnings hashlib resource xdrlib
_weakref heapq rexec xml
_weakrefset hmac rfc822 xmllib
abc hotshot rlcompleter xmlrpclib
aifc htmlentitydefs robotparser xxsubtype
antigravity htmllib runpy zipfile
anydbm httplib sched zipimport
argparse idlelib select zlib
array ihooks sets
ast imageop sgmllib
如果这有用,我的PYTHONPATH是:
['/home/username/Desktop/mycode', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
这是通过运行此程序找到的:
import sys
print sys.path
答案 0 :(得分:1)
似乎beautifulsoup已安装到PYTHONPATH上没有的目录中。试试这个临时解决方案:
sys.path.append('/usr/lib/python2.7/dist-packages')
help('modules')
您现在应该看到列出的bs4,并且可以使用。请记住,这不是一个永久的解决方案 - 您需要将目录添加到PYTHONPATH环境变量中,或者在PYTHONPATH上已有的目录中安装beautifulsoup。