[英]Python 2.7 and Flask - using functions from “Random” module returns “500 Internal Server Error” when using venv
I'm testing a web service written with python and flask. 我正在测试使用python和flask编写的Web服务。 Within that service I want to generate a random number. 在该服务中,我想生成一个随机数。 None of the solutions posted on the web seem to work, as if the "random" module does not work. 网络上发布的所有解决方案似乎都无法正常工作, 好像“随机”模块无法正常工作。 I checked, and there's no random.py or random.pyc within the folders around the webservice.py 我检查了一下,在webservice.py周围的文件夹中没有random.py或random.pyc
Here's how I start the web service: 这是我启动Web服务的方式:
$ . venv/bin/activate
$ python webservice.py
How can I fix random module not being available when running in a virtual environment? 在虚拟环境中运行时,如何解决随机模块不可用的问题?
import random
from random import randint
x = random.random()*100
x = randint(0,10)
print 'r' + x #does not work
Here's what's in the venv folder: 这是venv文件夹中的内容:
Check to see if the help("random") method will give a list. 检查help(“ random”)方法是否会给出列表。
a link to help. 帮助链接。
https://docs.python.org/2/library/random.html https://docs.python.org/2/library/random.html
Seems like you try to add string and integer. 好像您尝试添加字符串和整数。
Making a string out of a string and an integer in Python 在Python中用字符串和整数制成字符串
print 'x' + str(randint(0,10)) # try casting the int to string :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.