I tried to install beautifulsoup. I get such an error:
<-- snip -->
我试着安装beautifulsoup。我收到这样的错误:< - 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%
3 个解决方案
#1
You can test if a module is installed like so:
您可以测试模块是否安装如下:
$ python
>>> import modulename
#2
I'd try the following:
我尝试以下方法:
- Open Python shell
- Type
import <moduleName>
- Parse the results (no error, ImportError or some module loading error)
- Try to invoke any function from imported module (to see if module is correctly initialized).
打开Python shell
输入import
解析结果(没有错误,ImportError或某些模块加载错误)
尝试从导入的模块调用任何函数(以查看模块是否已正确初始化)。
Do you need something more sophisticated?
你需要更复杂的东西吗?
#3
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." print "\033[32mPython-prettytable Module [Available]\033[0m"
尝试:从prettytable导入PrettyTable,除了: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”除了:print“PrettyTable Python模块安装失败。”打印“\ 033 [32mPython-prettytable模块[可用] \ 033 [0m”
#1
You can test if a module is installed like so:
您可以测试模块是否安装如下:
$ python
>>> import modulename
#2
I'd try the following:
我尝试以下方法:
- Open Python shell
- Type
import <moduleName>
- Parse the results (no error, ImportError or some module loading error)
- Try to invoke any function from imported module (to see if module is correctly initialized).
打开Python shell
输入import
解析结果(没有错误,ImportError或某些模块加载错误)
尝试从导入的模块调用任何函数(以查看模块是否已正确初始化)。
Do you need something more sophisticated?
你需要更复杂的东西吗?
#3
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." print "\033[32mPython-prettytable Module [Available]\033[0m"
尝试:从prettytable导入PrettyTable,除了: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”除了:print“PrettyTable Python模块安装失败。”打印“\ 033 [32mPython-prettytable模块[可用] \ 033 [0m”