Python Forum

Full Version: Random module works in idle but not terminal.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all, I just started teaching myself python about 3 days ago. The language has been fun to learn. However, I have run into a bit of a problem. When I use textwrangler to write a script and run it from the terminal a traceback pops up:
Traceback (most recent call last):
File "while.py", line 3, in <module>
import random
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/random.py", line 42, in <module>
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ImportError: cannot import name 'log'

The script is very simple in textwrangler:
#!/usr/bin/env python3

import random

num = random.randint(1,10)

print(num)
I have tried using pip (and pip3) install random but then this error comes up:
Collecting random
Could not fetch URL https://pypi.python.org/simple/random/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping
Could not find a version that satisfies the requirement random (from versions: )
No matching distribution found for random

I have also tried all kinds of other commands using sudo but nothing seems to work. The very strange thing is that when I import random in the python shell idle, the program works and I can print a random number. If you are wondering, my package manager is homebrew and I am new to that as well.

Any help would be greatly appreciated!
The error message is
Quote:from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ImportError: cannot import name 'log'
Do you have more than one file named math.py?
(Apr-11-2018, 07:44 PM)ottowiser Wrote: [ -> ]I have tried using pip (and pip3) install random but then this error comes up:
random is part of the standard library, it will work without you installing anything.

Note, if you've named one of your files the same as what you're trying to import (math, random, etc), then python will import YOUR file, instead of what's in the standard library. So... don't name your files the same as things you intend to use :p
@woooee and @nilamo Okay I deleted my math.py file and my program ran. Thank you very much!