Unable to import decimal in Python 2.7 or Python 3.3 [duplicate]

2024/10/4 13:25:26

I am unable to import decimal in the terminal for Python 2.7 or 3.3.

Here are the errors I get:

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
Traceback (most recent call last):File "<stdin>", line 1, in <module>File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/decimal.py", line 3849, in <module>_numbers.Number.register(Decimal)
AttributeError: 'module' object has no attribute 'Number'

or Python 2.7

Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
Traceback (most recent call last):File "<stdin>", line 1, in <module>File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py", line 141, in <module>import numbers as _numbersFile "numbers.py", line 34, in <module>assert x / y == 2.5 # true division of x by y
AssertionError

How to I import decimal?

Answer

Is there numbers.py in current working directory?

That could be the reason of the problem, because that prevent import of standard library module numbers.

https://en.xdnf.cn/q/70601.html

Related Q&A

I Get ImportError: No module named pathlib, even after installing pathlib with pip

This is my first time asking on this site, so sorry if my question is not layed out correctlyy@DESKTOP-MQJ3NCT:~/Real-Time-Voice-Cloning$ python demo_toolbox.py Traceback (most recent call last):File &…

Python regex separate space-delimited words into a list

If I have a string = "hello world sample text"I want to be able to convert it to a list = ["hello", "world", "sample", "text"]How can I do that with re…

Naive install of PySpark to also support S3 access

I would like to read Parquet data stored on S3 from PySpark.Ive downloaded spark from here:http://www.apache.org/dist/spark/spark-2.1.0/spark-2.1.0-bin-hadoop2.7.tgzAnd installed it to Python naivelycd…

Multiprocessing Pool hangs if child process killed

I launched a pool of worker processes and submitted a bunch of tasks. The system ran low on memory and the oomkiller killed one of the worker processes. The parent process just hung there waiting for t…

What does sys.maxunicode mean?

CPython stores unicode strings as either utf-16 or utf-32 internally depending on compile options. In utf-16 builds of Python string slicing, iteration, and len seem to work on code units, not code po…

How to detect dialogs close event?

Hi everyone.I am making a GUI application using python3.4, PyQt5 in windows 7. Application is very sample. User clicks a main windows button, information dialog pops up. And when a user clicks informat…

How to Make a Portable Jupyter Slideshow

How do I make a Jupyter slide show portable? I can serve the slideshow locally, but I cant send that to anyone and have it work with all the images, slide animation functionality, etc. I am using jupy…

How to animate a bar char being updated in Python

I want to create an animated, stacked bar chart.There is a great tutorial, which shows how to animate line graphs.However, for animating bar charts, the BarContainer object, does not have any attribute…

Add text to end of line without loading file

I need to store information into a very big file, in form of many dictionaries. Thats not so important, is just to say that I tried to first get all the data into these dictionaries and I run out of me…

How does one use `dis.dis` to analyze performance?

Im trying to use pythons dis library to experiment with & understand performance. Below is an experiment i tried, with the results.import disdef myfunc1(dictionary):t = tuple(dictionary.items())ret…