[英]How can I test that I have a Python module successfully installed?
I tried to install beautifulsoup. 我试图安装beautifulsoup。 I get such an error:
我收到这样的错误:
<-- snip --> <-片段->
raise MissingSectionHeaderError(fpname, lineno, line)
ConfigParser.MissingSectionHeaderError: File contains no section headers.
file: /Users/Sam/.pydistutils.cfg, line: 1
'install_lib = ~/Library/Python/$py_version_short/site-packages\n'
I get an similar error as I run my Python code in vim by: :!python % 我在vim中运行Python代码时遇到类似的错误::!python%
You can test if a module is installed like so: 您可以像这样测试是否安装了模块:
$ python
>>> import modulename
I'd try the following: 我会尝试以下方法:
import <moduleName>
import <moduleName>
Do you need something more sophisticated? 您需要更复杂的东西吗?
try: from prettytable import PrettyTable except: try: print "\\033[31mPython-prettytable Module [Not Available]\\033[0m" os.system('sudo apt-get install python-setuptools') os.system('sudo easy_install prettyTable') print "\\033[33mPython-prettytable Module [Installed]\\033[0m" except: print "PrettyTable Python Module Installation failed." 尝试:从prettytable导入PrettyTable除外:尝试:打印“ \\ 033 [31mPython-prettytable模块[不可用] \\ 033 [0m”] os.system('sudo apt-get install python-setuptools')os.system('sudo easy_install prettyTable')打印“ \\ 033 [33mPython-prettytable模块[已安装] \\ 033 [0m””,但:打印“ PrettyTable Python模块安装失败。” print "\\033[32mPython-prettytable Module [Available]\\033[0m"
打印“ \\ 033 [32mPython-prettytable模块[可用] \\ 033 [0m”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.