无法使用Python导入模块

时间:2016-08-02 18:54:28

标签: python

我尝试过导入模块,直到现在我才运气不好。我的所有导入都不起作用,因为Python似乎无法找到它们。如果我将导入目录粘贴到与我的脚本相同的文件夹上,它将会运行,否则就不会。

我跑了:

sys.path

得到了这个尴尬的结果:

['', '/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']

我非常相信我的Python安装并没有那么好。什么是最好的转变?

看起来很混乱。谢谢!

2 个答案:

答案 0 :(得分:1)

我猜您正在尝试导入非标准库。如果这是你想要做的,你必须先运行

pip install foo

在您系统的相应控制台中。在可能是cmd或powershell的窗口上。

答案 1 :(得分:-1)

这个问题构造不当,提供的信息不足。但是....如果你要导入一个模块用于你的代码,你应该写一些像......

 import 'module'
 module.usemodule(whatever)