In Python 3.x, use int instead of long.

From What’s New In Python 3.0, Integers:

  • PEP 237: Essentially, long renamed to int. That is, there is only one built-in integral type, named int; but it behaves mostly like the old long type.
Answer from Jon-Eric on Stack Overflow
🌐
GitHub
github.com › pytorch › pytorch › issues › 1166
NameError: name 'long' is not defined · Issue #1166 · pytorch/pytorch
April 1, 2017 - Traceback (most recent call last): ... "/home/keith/.virtualenvs/pp/lib/python3.5/site-packages/torchvision/utils.py", line 28, in make_grid size = torch.Size(torch.Size([long(numImages)]) + tensorlist[0].size()) NameError: name 'long' is not defined...
Author: pytorch
Discussions

NameError: name 'long' is not defined in python\google\protobuf\internal\reflection_test.py:639
Hi, Python 3.x has no long type. python\google\protobuf\internal\reflection_test.py 632 try: 633 integer_64 = long 634 except NameError: # Python3 635 integer_64 = int 636 if struct.calcsize('L') =... More on github.com
🌐 github.com
2
May 8, 2016
django - Long type in Python-3, NameError: name 'long' is not defined - Stack Overflow
And all integers are "long" in Python 3 (the type is renamed to int). Assume that integers have infinite precision in Python. To assign and print large integer in Python, just assign and print it: Copyx = 2**100 print(x) # -> 1267650600228229401496703205376 · It works on both Python 2 and 3. The result is the same. ... Save this answer. ... Show activity on this post. you no need to define ... More on stackoverflow.com
🌐 stackoverflow.com
NameError: name 'long' is not defined When Using Python 3
When using Python 3 instead of Python 2.7 the following error appears when invoking the grandfatherson.dates_to_delete function: File "/usr/local/lib/python3.4/dist-packages/grandfatherson/__i... More on github.com
🌐 github.com
4
April 18, 2016
name 'long' is not defined
python 3.8 install from pip, run import encounter name 'long' is not defined error from protobuf_to_dict import protobuf_to_dict NameError Traceback (most recent call last) in ----> 1 fr... More on github.com
🌐 github.com
4
December 16, 2020
People also ask

What is Python NameError and what causes it?
NameError is raised when Python encounters a name (variable, function, class) that hasn't been defined in the current scope. Most common causes: typo in variable name, using a variable before assigning it, missing import, or referencing a variable that was defined inside a function but accessed outside it.
🌐
itsourcecode.com
itsourcecode.com › home › nameerror: name long is not defined
Fix NameError: long is Not Defined (2026 Python 3)
What is the difference between NameError and AttributeError?
NameError: the name itself doesn't exist anywhere in scope (typo, missing import, scope issue). AttributeError: the name exists and points to an object, but that object has no such attribute/method (typo on method name, wrong object type). NameError is about the variable; AttributeError is about what's inside it.
🌐
itsourcecode.com
itsourcecode.com › home › nameerror: name long is not defined
Fix NameError: long is Not Defined (2026 Python 3)
Why does my variable work in one cell but not another (Jupyter)?
Jupyter kernels keep state between cells. If you defined X in cell 5 and run cell 3 later, X exists. But after Kernel-Restart, only the cells you re-run define their variables. Always run cells top-to-bottom on a fresh kernel before submitting. Use 'Restart and Run All' to verify your notebook is reproducible.
🌐
itsourcecode.com
itsourcecode.com › home › nameerror: name long is not defined
Fix NameError: long is Not Defined (2026 Python 3)
🌐
Itsourcecode
itsourcecode.com › home › nameerror: name long is not defined
Fix NameError: long is Not Defined (2026 Python 3)
July 12, 2026 - Fix Python 3 "NameError: name 'long' is not defined" by using int instead (long removed in Python 3). 2026 fix.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › using the raspberry pi › troubleshooting
NameError: name 'long' is not defined - Raspberry Pi Forums
Basically the old int was removed and long was renamed int for Python 3. Oh wow I just changed some of the code and used python2.7 to run the script and it works! Thank you for your help! Thanks B.Goode! That's something I obviously should have done... I was just worried I'd be wasting my time only because he hasn't replied to the other issues others have had!
🌐
GitHub
github.com › protocolbuffers › protobuf › issues › 1504
NameError: name 'long' is not defined in python\google\protobuf\internal\reflection_test.py:639 · Issue #1504 · protocolbuffers/protobuf
May 8, 2016 - Hi, Python 3.x has no long type. python\google\protobuf\internal\reflection_test.py 632 try: 633 integer_64 = long 634 except NameError: # Python3 635 integer_64 = int 636 if struct.calcsize('L') == 4: 637 # Python only has signed ints, ...
Author: protocolbuffers
Top answer
1 of 5
14

The long() function is no longer supported by Python 3 (no pun intended). It only has one built-in integral type, named int; but it behaves mostly like the old long type. So you just need to use int() built-in function in python-3.x.

Also for more information here are the complete list of changes on integer type in python-3.x:

  • PEP 0237: Essentially, long renamed to int. That is, there is only one built-in integral type, named int; but it behaves mostly like the old long type.

  • PEP 0238: An expression like 1/2 returns a float. Use 1//2 to get the truncating behavior. (The latter syntax has existed for years, at least since Python 2.2.)

  • The sys.maxint constant was removed, since there is no longer a limit to the value of integers. However, sys.maxsize can be used as an integer larger than any practical list or string index. It conforms to the implementation’s “natural” integer size and is typically the same as sys.maxint in previous releases on the same platform (assuming the same build options).

  • The repr() of a long integer doesn’t include the trailing L anymore, so code that unconditionally strips that character will chop off the last digit instead. (Use str() instead.)

  • Octal literals are no longer of the form 0720; use 0o720 instead.

2 of 5
1

Forget about long vs. int or about lL suffixes. Python 2.7 will promote int to long if necessary. And all integers are "long" in Python 3 (the type is renamed to int).

Assume that integers have infinite precision in Python.

To assign and print large integer in Python, just assign and print it:

x = 2**100
print(x) # -> 1267650600228229401496703205376

It works on both Python 2 and 3. The result is the same.

🌐
GitHub
github.com › ecometrica › grandfatherson › issues › 3
NameError: name 'long' is not defined When Using Python 3 · Issue #3 · ecometrica/grandfatherson
April 18, 2016 - File "/usr/local/lib/python3.4/dist-packages/grandfatherson/__init__.py", line 220, in dates_to_delete firstweekday=firstweekday, now=now) File "/usr/local/lib/python3.4/dist-packages/grandfatherson/__init__.py", line 204, in dates_to_keep firstweekday=firstweekday, now=now) File "/usr/local/lib/python3.4/dist-packages/grandfatherson/__init__.py", line 172, in to_keep filters.Minutes.filter(datetimes, number=minutes, now=now) | File "/usr/local/lib/python3.4/dist-packages/grandfatherson/filters.py", line 55, in filter if number < 0 or not isinstance(number, (int, long)): NameError: name 'long' is not defined
Author: ecometrica
Find elsewhere
🌐
GitHub
github.com › benhodgson › protobuf-to-dict › issues › 20
name 'long' is not defined · Issue #20 · benhodgson/protobuf-to-dict
December 16, 2020 - python 3.8 install from pip, run import encounter name 'long' is not defined error from protobuf_to_dict import protobuf_to_dict NameError Traceback (most recent call last) in ----> 1 from protobuf_to_dict import protobuf_to_dict ~/minic...
Author: benhodgson
🌐
GitHub
github.com › tensorflow › privacy › issues › 8
Python3 rdp_accountant: "name 'long' is not defined" · Issue #8 · tensorflow/privacy
January 3, 2019 - Python3 rdp_accountant: "name 'long' is not defined"#8 · Copy link · bergen · opened · on Jan 3, 2019 · Issue body actions · rdp_accountant.py contains an assert statement assert isinstance(alpha, (int, long)). However, Python3 doesn't have a long type anymore.
Author: tensorflow
Author: aleju
🌐
GitHub
github.com › rootpy › rootpy › issues › 778
NameError: name 'long' is not defined using python3 · Issue #778 · rootpy/rootpy
November 2, 2017 - Traceback (most recent call last): ... canonify_slice(s, n) File "/home/jodamp/.local/lib/python3.6/site-packages/rootpy/plotting/hist.py", line 43, in canonify_slice if isinstance(s, (int, long)): NameError: name 'long' is not defined...
Author: rootpy
🌐
GitHub
github.com › ansible › ansible › issues › 20257
python3 NameError: name 'long' is not defined · Issue #20257 · ansible/ansible
January 14, 2017 - found: NameError: name 'long' is not defined To change the : #vim /usr/local/python-3.6.0/lib/python3.6/site-packages/ansible/plugins/filter/core.py +204 if isinstance(end, (int, long)): change: if isinstance(end, int):
Author: ansible
🌐
Righteousshot
righteousshot.com › zlrnja › 233acd-long'-is-not-defined-python
long' is not defined python
When I run this code in python 2.7, I get this error: Traceback (most recent call last): File "C:\Python26\Lib\site-packages\pyutilib.subprocess-3.5.4\setup.py", line 30, in · long_d Already on GitHub? msg64889 - Author: Hirokazu Yamamoto (ocean-city) * Date: 2008-04-03 04:02; Oh, I forgot this. NameError: name 'long' is not defined in python\google\protobuf\internal\reflection_test.py:639, # Python only has signed ints, so 32-bit python can't fit an uint32, # 64-bit python can fit uint32 inside an int.
🌐
Stack Overflow
stackoverflow.com › questions › 40195430 › python-error-while-trying-to-run-a-script-nameerror-name-long-is-not-defined
Python Error while trying to run a script: NameError: name 'long' is not defined - Stack Overflow
python mavlogdump.py flightdata.bin -f --format "csv" The method I use to run this code is that I have mavlogdump.py and flightdata.bin in the same folder. I point the CMD to that folder and use the line above to try and execute the script. However no matter what I have tried I get an error of: NameError: name 'long' is not defined.
🌐
GitHub
github.com › behalf-oss › behave2cucumber › issues › 6
'long' not defined in Python 3.x · Issue #6 · behalf-oss/behave2cucumber
May 17, 2017 - python3.5/site-packages/behave2cucumber/init.py", line 39, in format_level item["result"]["duration"] = long(item["result"]["duration"] * 1000000000) NameError: name 'long' is not defined
Author: behalf-oss
🌐
Autodesk Community
forums.autodesk.com › t5 › maya-programming-forum › long-quot-is-not-defined › td-p › 10960001
Solved: 'long" is not defined - Autodesk Community
February 19, 2022 - Reply · Reply · 0 Likes · Like ... Subscribe · Mute · Subscribe to RSS Feed · Permalink · Print · Report · Accepted solution · long has been renamed int in Python 3 ·...
🌐
Apache JIRA
issues.apache.org › jira › browse › SINGA-418
[SINGA-418] Unsupportive type 'long' in python3. - ASF Jira
When I trained the mnist of examples, "NameError: name 'long' is not defined" occurred. ... Python3.6 is used.
🌐
Csbusinessolutions
csbusinessolutions.com › home › long' is not defined python
long' is not defined python
January 19, 2021 - My question is: should long be integer_64? You signed in with another tab or window. If one were to write x:= y, it is not that x and y share a relationship of quantitative equality but that x is defined to be whatever value y is. Windows 7 (and old installers not restricted to 64-bit Windows). An integer object in Python is represented internally by the structure PyIntObject.
🌐
Zeth
zeth.net › 2014 › 05 › 27 › python_long_type.html
Python’s Disappearing Long Type — Zeth.net
May 27, 2014 - Python’s long type does not map directly to a C type, it is a custom type implemented in the Python source code somewhere which I guess uses a C struct or whatever.
🌐
GitHub
github.com › mpmath › mpmath › issues › 344
[Python 3.5] NameError: name 'long' is not defined · Issue #344 · mpmath/mpmath
January 19, 2017 - Hi there, I'm not sure why this happens, but on my python 3.5 install on OS X you use the following code to detect python version: mpmath/libmp/backend.py, line 36 try: xrange python3 = False e...
Author: mpmath