概述
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中运行但在现实生活中失败,因为无法导入模块...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复