gpt4 book ai didi

python - 崇高 - ImportError : No module named

转载 作者:太空宇宙 更新时间:2023-11-04 08:58:06 26 4
gpt4 key购买 nike

我对 python 和 sublime 还很陌生。我目前正在观看培训视频并跟进。我遇到了很多关于 sublime 的问题,但无法通过这个问题。尝试将模块导入我在训练期间创建的解释器时出现错误。 wiper.py 文件位于 Users/marcus/Documents/Scripts/。我已经在下面打印了当前路径。有人可以帮助我吗?

>>> import wiper 
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named wiper
>>> print ('PATH = ' + os.environ['PATH'])
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin:/Users/marcus/Documents/Scripts//.rvm/bin:de here

一些附加信息。我导入了 sys 并运行了 sys.path 并获得了这些信息。我不知道这是否有帮助。

>>> import sys
>>> 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']

最佳答案

您需要将 /Users/marcus/Documents/Scripts 添加到您的 Python 模块搜索路径。 PATH 仅供您的 shell 查找可执行文件,而不是 Python 模块。

您可以设置 PYTHONPATH environment variable :

export PYTHONPATH='/Users/marcus/Documents/Scripts'

您可以只为您的 Sublime Text 项目设置该环境变量;在您的项目设置中添加:

"build_systems":
[
{
"name": "Python",
"shell_cmd": "python -u \"$file\"",
"env": {
"PYTHONPATH": "/Users/marcus/Documents/Scripts"
},
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
]

或使用相同类型的设置来创建全局 build system .

另一种方法是让您的脚本通过插入 sys.path 以编程方式添加路径:

import sys
sys.path.insert(0, '/Users/marcus/Documents/Scripts')
import wiper

关于python - 崇高 - ImportError : No module named,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28300286/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com