I have a script that runs fine in the Python Shell, but when double clicked it fails to import the PIL module(but it does import the PIL module in the Shell).
What is wrong? Do I need a different shebang? I am on Windows 7:
#!/usr/bin/env python
"""
"""
try:
from PIL import Image
import os
import datetime
import time
except Exception, e:
raw_input(str(e))
# Running this script in the Shell, the code gets to here
# Running this script in real life (just double click it) it prints "no module PIL"
解决方案
Add the lines
import sys
print sys.executable
to your code. You'll see that it's a different python executable when you run it in the shell, vs. double clicking the .py file.
If you want to control which installed version of python is used to run your script, rather than simply running the script, type something like the following in a windows command window.
c:python27python.exe scriptname.py
replacing the python directory and script name as appropriate.
最后
以上就是无私康乃馨最近收集整理的关于shell中执行python失败,Python脚本:在Shell中运行但在现实生活中失败,因为无法导入模块...的全部内容,更多相关shell中执行python失败,Python脚本:在Shell中运行但在现实生活中失败,因为无法导入模块内容请搜索靠谱客的其他文章。
发表评论 取消回复