我是靠谱客的博主 无私康乃馨,最近开发中收集的这篇文章主要介绍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中运行但在现实生活中失败,因为无法导入模块...所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部