我尽可能使用argparse写成最小的python程序。只有三行。
import argparse
if __name__ == "__main__":
print "Hello World"
收到以下错误:
File" /Users/pfarrell/sandbox/dbms/extractor/src/extractor.py" ;, line 2,在 import argparse ImportError:没有名为argparse的模块
这是我写过的第一个python程序,所以我很容易相信我没有正确设置一些python库路径等。
这是在OS-X上运行
python --version
Python 2.7.1
pfarrell@way:~/sandbox/dbms/extractor/src$ python -c "import argparse; print argparse"
<module 'argparse' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.pyc'>
更多测试(感谢评论)
在shell中显式运行它,但在netbeans中运行它会失败:
python extractor.py -h
Hello World
usage: extractor.py [-h]
optional arguments:
-h, --help show this help message and exit
将其作为脚本运行会显示完全不同的路径。看起来netbeans设置需要调整或两个
./extractor.py -h
/Users/pfarrell/sandbox/dbms/extractor/src
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib- scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/Library/Python/2.7/site-packages
Hello World
/Users/pfarrell/sandbox/dbms/extractor/src
/Users/pfarrell/Library/Application Support/NetBeans/7.2.1/jython-2.5.1/Lib
/Users/pfarrell/Library/Application Support/NetBeans/7.2.1/jython-2.5.1/Lib/site-packages
/Users/pfarrell/sandbox/dbms/extractor/src
__classpath__
__pyclasspath__/
Hello World
答案 0 :(得分:1)
感谢所有人。正如@sberry建议的那样,这条路有很多问题。 我发现netbeans默认为jpython,这是一个较旧的2.5版本。它也可以使用标准的python 2.7.1,当我使用它时,一切都是幸福和快乐
非常感谢。