Python Forum
Random module works in idle but not terminal.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random module works in idle but not terminal.
#1
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!
Reply
#2
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?
Reply
#3
(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
Reply
#4
@woooee and @nilamo Okay I deleted my math.py file and my program ran. Thank you very much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Launch Python IDLE Shell from terminal Pavel_47 5 1,254 Feb-17-2023, 02:53 PM
Last Post: Pavel_47
  Module which run in PyCharm but not as exe or terminal. diegoctn 3 6,549 Jul-13-2021, 04:03 AM
Last Post: Harshith
  keyboard module doesn't work in the microsoft version terminal of python. username 1 2,821 Feb-25-2021, 05:19 PM
Last Post: Larz60+
  IDLE editing window no longer works chris1 2 2,221 Feb-06-2021, 07:59 AM
Last Post: chris1
  <while> cycle is not interrupted when using the <random>module ShityCoder 3 2,168 Sep-04-2020, 04:05 PM
Last Post: ShityCoder
  Some help with Classes and the random module please? :) AlluminumFoil 2 2,189 Jan-08-2020, 11:03 PM
Last Post: AlluminumFoil
  Coloured text in the terminal works in Linux but not Windows Flexico 2 2,701 Aug-26-2019, 10:44 PM
Last Post: Flexico
  Can't Get Random Module! Pls Help! VictorVictus 1 7,162 Aug-24-2019, 10:20 AM
Last Post: snippsat
  Code works in IDLE, appears to work in CMD, but won't produce files in CMD/Windows ChrisPy33 3 3,249 Jun-12-2019, 05:56 AM
Last Post: ChrisPy33
  uising python zero with IDLE I get an error of 'module not found' Brian123 1 3,917 Apr-24-2019, 09:21 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020