我是靠谱客的博主 无私康乃馨,这篇文章主要介绍shell中执行python失败,Python脚本:在Shell中运行但在现实生活中失败,因为无法导入模块...,现在分享给大家,希望可以做个参考。

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中运行但在现实生活中失败,因为无法导入模块内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部