Python:为什么不能导入 random模块,求解,谢谢!

andr12345 2012-03-19 10:31:15
import random



执行提示:ImportError:No moudle name random
...全文
3435 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rlay_2 2012-03-19
  • 打赏
  • 举报
回复
配置好了环境变量,就可以了..
andr12345 2012-03-19
  • 打赏
  • 举报
回复
自己解决了 增加搜索路径
sys.path.append("你的python lib路径")

关贴!
andr12345 2012-03-19
  • 打赏
  • 举报
回复
我估计是JDK包了python2.6,不知道是不是这样的,自己猜测
andr12345 2012-03-19
  • 打赏
  • 举报
回复
我是用monkeyrunner执行的,不是用python执行的.用python执行没有问题.
monkeyrunner的原文件是:
@echo off
rem Copyright (C) 2010 The Android Open Source Project
rem
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem don't modify the caller's environment
setlocal

rem Set up prog to be the path of this script, including following symlinks,
rem and set up progdir to be the fully-qualified pathname of its directory.
set prog=%~f0

rem Change current directory and drive to where the script is, to avoid
rem issues with directories containing whitespaces.
cd /d %~dp0

rem Check we have a valid Java.exe in the path.
set java_exe=
call lib\find_java.bat
if not defined java_exe goto :EOF

set jarfile=monkeyrunner.jar
set frameworkdir=
set libdir=

if exist %frameworkdir%%jarfile% goto JarFileOk
set frameworkdir=lib\

if exist %frameworkdir%%jarfile% goto JarFileOk
set frameworkdir=..\framework\

:JarFileOk

set jarpath=%frameworkdir%%jarfile%

if not defined ANDROID_SWT goto QueryArch
set swt_path=%ANDROID_SWT%
goto SwtDone

:QueryArch

for /f %%a in ('%java_exe% -jar %frameworkdir%archquery.jar') do set swt_path=%frameworkdir%%%a

:SwtDone

if exist %swt_path% goto SetPath
echo SWT folder '%swt_path%' does not exist.
echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
exit /B

:SetPath

call %java_exe% -Xmx512m -Djava.ext.dirs=%frameworkdir%;%swt_path% -Dcom.android.monkeyrunner.bindir=..\framework -jar %jarpath% %*
bullswu 2012-03-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 andr12345 的回复:]
我也搞不懂,乘没结帖我追加个问题哈>

编译执行的时侯,出了这么个错误:
import linecache
SyntaxError:("'with' will become a reserved keyword in Python 2.6",('c:\\Python27\\lib\\linecache.py',127,8,''))

这个是什么原因,怎么解决.
PS:程序里有impo……
[/Quote]

打包套件内部有版本冲突。
你看下python是在哪个版本上编译的,套件内的又是哪个版本的。明显你用了2.6和2.7
andr12345 2012-03-19
  • 打赏
  • 举报
回复
我也搞不懂,乘没结帖我追加个问题哈>

编译执行的时侯,出了这么个错误:
import linecache
SyntaxError:("'with' will become a reserved keyword in Python 2.6",('c:\\Python27\\lib\\linecache.py',127,8,''))

这个是什么原因,怎么解决.
PS:程序里有import random并没有import linecache语句
zengna_com 2012-03-19
  • 打赏
  • 举报
回复
自带的模块怎么找不到呢
angel_su 2012-03-19
  • 打赏
  • 举报
回复
比较好奇lz的执行环境,为啥默认没有包含标准模块路径,还要手动?

37,741

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧