Windows问题与python绝对导入错误

还有许多其他问题和答案解释了Python绝对导入的细微差别。从这些,我有一个在Linux上运行良好的大型项目。但是要使Windows可执行文件,必须在Windows上编译它,并且在此平台上绝对引用似乎会中断。我认为问题是环境问题,但我不知道为什么。

# I've tried both setting and unsetting the python path to the project,# which then shows up in > python -c "import sys; print(sys.path)"
> $env:PYTHONPATH = "C:\Users\Me\Workspace\my_proj"
# I've tried both with and without an __init__.py file in Workspace\

制作一个玩具项目来调试它: my_proj\目录包含__init__.pya.pyb.py 如果a.py包含行def foo(): print('Awesome'),那么对于b.py,我可以将其导入为import a没问题:import a; a.foo(),在任何目录中,都没有__init__.py

但是要使用import my_proj.afrom my_proj import a,从my_proj\Workspace\目录中调用带有或不带有__init__.py文件的目录都无效。

如果python在python path / sys.path上可以看到目录my_proj\,那为什么不起作用?

lsw8142 回答:Windows问题与python绝对导入错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3157987.html

大家都在问