gpt4 book ai didi

python - 为什么我的脚本目录不在 Python sys.path 中?

转载 作者:行者123 更新时间:2023-11-28 18:09:45 24 4
gpt4 key购买 nike

python 3.6.5
我知道这个:Why does my python not add current working directory to the path?但问题在于他正在做更复杂的事情(指的是子文件夹但从主文件夹执行)。答案要么是简化事情,要么是添加包定义。

而且选择的答案甚至说:“添加的是脚本的目录”

但是,我的问题实际上更简单:我的脚本目录没有添加。

基本上网上所有的教程都是这样说的:import mymodule
当我这样做时,出现名称错误...

我的文件夹结构:

C:/Projects/interner
interner.py # this is the main program body
aux.py # this is the auxiliary file I would like to import into the above

我已经尝试在 interner.py 中编写“import aux”,也尝试使用交互式控制台:

cd c:/Projects/interner
python
import aux

无济于事(ModuleNotFoundError:没有名为“aux”的模块)

我的系统路径:

['C:\\Tools\\Python\\python365\\python36.zip', 'C:\\Tools\\Python\\python365']

(从脚本内部和交互式控制台)

你能告诉我为什么我不能导入本地脚本吗?是因为我的 sys.path 缺少 PWD 吗?如果是这样,为什么会丢失它?

编辑:这样做是为了帮助调查:

>>> import os; print(os.listdir("."))
['aux.py', 'hw.py', 'interner.py', 'my_funcs.py']

最佳答案

我认为这是一个 Python 错误,特定于可嵌入(没有安装程序的 ZIP 文件)Windows 发行版。我已经提交了 https://bugs.python.org/issue34841 .

从分发中删除 python37._pth 文件(在你的情况下可能是 python36._pth)为我修复了它。

关于python - 为什么我的脚本目录不在 Python sys.path 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51403126/

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