简体   繁体   中英

Jython no module named random

I'm working on a server that is made off of Java. At certain points of time (ie someone clicks on a object in the game for example), the server will load a script made using Jython. I'm having trouble getting the script to work, mainly because one imports the module random. Here is the script:

from resources.common import RadialOptions

import sys
import random

def createRadial(core, owner, target, radials):

 radials.add(RadialOptions(0, 21, 1, '')) #Use
 radials.add(RadialOptions(0, RadialOptions.diceRoll, 3, '@dice/dice:dice_roll_single'))

return

def handleSelection(core, owner, target, option):
  if option == RadialOptions.diceRoll or 21:
    stringOptions = ['red', 'blue']
    owner.sendSystemMessage('Your chance cube rolled the color ' + random.choice(stringOptions) , 0)
return

When the server is loaded up and the script is called, I receive an import error saying there is no module named "random". It doesn't matter what module I call that exists within Jython/Python, it won't except anything but sys and java classes.

I then went ahead and opened up a PyDev console and tried to see if I was able to import random. It was successful.

How come the PyDev console will let me import random or any other module, but not the server when it calls the script?

Try in PyDev entering:

import sys
print sys.path

then add the same to your script - before the problem and compare the two, if they are the same in both cases search the elements of both for random on your local machine and the one your server runs on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM