从命令行调用时找不到python模块
我刚开始学习Python 在c:\Python27中,我创建了我的第一个hello.py脚本 当我在命令行中键入以下内容时,它会起作用:从命令行调用时找不到python模块,python,Python,我刚开始学习Python 在c:\Python27中,我创建了我的第一个hello.py脚本 当我在命令行中键入以下内容时,它会起作用: c:\Python27 python hello.py c:\Python python mymodule.py 现在我创建了另一个脚本,但在不同的目录中。此目录位于 蟒蛇 mymodule.py: print("general") def fone(): print("special line") 扩展hello.py脚本时:
c:\Python27 python hello.py
c:\Python python mymodule.py
现在我创建了另一个脚本,但在不同的目录中。此目录位于
蟒蛇
mymodule.py:
print("general")
def fone():
print("special line")
扩展hello.py脚本时:
import mymodule
print "Hello"
mymodule.fone()
找到mymodule脚本/模块并正确导入,因此PYTHONPATH似乎正常
但当我在命令行键入时:
c:\Python27 python hello.py
c:\Python python mymodule.py
我得到一个错误:
python: can't open file 'mymodule.py': [Errno 2] No such file or directory
为什么会这样
非常感谢您的帮助您应该指定文件的完整路径,除非它位于当前工作目录中
python C:\path\to\mymodule.py
或者,如果模块位于目录中(在PYTHONPATH中列出),则可以使用python-m…
:
运行
python mymodule.py
时,它会在当前目录中查找mymodule.py
。您需要指定完整路径