Python no module named builtin

Why «ImportError: No module named builtins» appears after importing hive from PyHive package?

I have a simple question to ask. I have been trying to execute HIVE queries from Python using impyla package. But I stuck into cursor problem, already a question has been asked on stackoverflow. In this question, a user answered and advised to use PyHive instead. Therefore, now I am trying to execute HIVE queries from Python using PyHive. But unluckily, I am stuck at another issue which seems to be not that complicated. As soon as I execute the following line in python I get an error:

In [18]: from pyhive import hive Traceback (most recent call last): File "", line 1, in from pyhive import hive File "build\bdist.win32\egg\pyhive\hive.py", line 13, in File "build\bdist.win32\egg\pyhive\common.py", line 8, in ImportError: No module named builtins 

1 Answer 1

In python 3 the module __builtin__ was renamed to builtins .

It is possible that you have installed a python 3 package and are trying to run it with python 2.

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.27.43548

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Читайте также:  Ссылки без подчеркивания

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named ‘__builtin__’ #26

No module named ‘__builtin__’ #26

Comments

while I was trying to run on debian 10 the simple example which has been provided in pypi I encountered the following error:

File "/home/sh/spyder/temp.py", line 5, in from pyqtconsole.console import PythonConsole File "/home/sh/anaconda3/lib/python3.7/site-packages/pyqtconsole/console.py", line 10, in from .interpreter import PythonInterpreter File "/home/sh/anaconda3/lib/python3.7/site-packages/pyqtconsole/interpreter.py", line 14, in from __builtin__ import exit # py2 ModuleNotFoundError: No module named '__builtin__' 

then I search for solution like changing to: __ builtins __, __ builtin __, __ builtin __ . __ dict __
but still have the same problem.

The text was updated successfully, but these errors were encountered:

first of all I have to mention that I’m using python37. The first command you mentioned works fine. but the second one returns the following error:

Traceback (most recent call last): File "", line 1, in AttributeError: module 'builtins' has no attribute '__file__' 

by the way, I could easily run it on windows 10.

If python3 -c «from builtins import exit» works, you should never get to the line trying to import from __builtin__ . Are you sure you’re using the same Python for both? From your stacktrace above, you seem to be using Anaconda’s Python.

yes I’m trying it with spyder. but the two code snippets you sent, I tried them on my ordinary terminal.
Again when I’m trying the code out of spyder (in terminal) I see the following message:

Traceback (most recent call last): File "./n1.py", line 10, in console.eval_in_thread() File "/home/sh/anaconda3/lib/python3.7/site-packages/pyqtconsole/console.py", line 582, in eval_in_thread self.interpreter.exec_, Qt.ConnectionType.QueuedConnection) AttributeError: type object 'ConnectionType' has no attribute 'QueuedConnection' 

The last traceback appears to be the same issue as reported in #23 that appears for PyQt5

However, this doesn’t really explain the first traceback you showed. Can you reproduce and describe the exact circumstances under which you obtain the initially reported error?

yes I can definitely reproduce that error. As I mentioned earlier I am using Debian 10, and im trying to run the code on Spyder IDE, and I have python3.7. if you need any extra information which I didn’t provide ask to me to give more information about my machine and system. my first comment is not the complete error message, so I post it again here:

runfile('/home/sh/spyder/temp03.py', wdir='/home/sh/spyder') Traceback (most recent call last): File "", line 1, in runfile('/home/sh/spyder/temp03.py', wdir='/home/sh/spyder') File "/home/sh/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile execfile(filename, namespace) File "/home/sh/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "/home/sh/spyder/temp03.py", line 5, in from pyqtconsole.console import PythonConsole File "/home/sh/anaconda3/lib/python3.7/site-packages/pyqtconsole/console.py", line 10, in from .interpreter import PythonInterpreter File "/home/sh/anaconda3/lib/python3.7/site-packages/pyqtconsole/interpreter.py", line 14, in from __builtin__ import exit # py2 ModuleNotFoundError: No module named '__builtin__' 

I installed spyder and can reproduce. It seems that spyder deletes exit from the builtins:

>>> import builtins >>> print('exit' in dir(builtins)) False

Not sure why they are doing this, probably so that it doesn’t conflict with their custom exit.

Normally, I would consider this a misfeature of spyder that doesn’t warrant a fix here, but it should be easy enough to do by simply defining a custom exit function that just raises SystemExit instead of importing it. I can do the patch/PR later or tomorrow.

Источник

ModuleNotFoundError:No module named ‘__builtin__’ in conda

I have looked at other answers such as conda install future and others but none seem to solve this error. Everything was working till yesterday but today when I am trying to run my script I get this error. I initially thought that I had multiple pandas packages from pip and conda so I uninstalled from both and then installed via conda again. But the error still persists. I have installed python 3.6 as a separate environment in anaconda 2.

Traceback (most recent call last): File "/Users/amit/anaconda2/envs/python36/lib/python3.6/site-packages/pandas/compat/__init__.py", line 49, in import __builtin__ as builtins ModuleNotFoundError: No module named '__builtin__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "main.py", line 18, in from nameserver import NameServer File "/Users/amit/Work/ml/marl/nameserver.py", line 4, in import pandas as pd File "/Users/amit/anaconda2/envs/python36/lib/python3.6/site-packages/pandas/__init__.py", line 23, in from pandas.compat.numpy import * File "/Users/amit/anaconda2/envs/python36/lib/python3.6/site-packages/pandas/compat/__init__.py", line 62, in import http.client as httplib ModuleNotFoundError: No module named 'http.client' 

============= EDIT 1 Following @EvgenyPogrebnyak’s advice I created a new env named py36 . I tried running the print statement python -c «import pandas as pd; print(pd.__version__)» statement from the home directory or infact any other directory it runs fine but when I run it from my project directory I get this particular error, which is weird.

amit:~ $source activate py36 (py36) amit:~ $python -c "import pandas as pd; print(pd.__version__)" 0.23.0 (py36) amit:~ $cd Work/ml/marl/ (py36) amit:~/Work/ml/marl $python -c "import pandas as pd; print(pd.__version__)" Traceback (most recent call last): File "/Users/amit/anaconda2/envs/py36/lib/python3.6/site-packages/pandas/compat/__init__.py", line 49, in import __builtin__ as builtins ModuleNotFoundError: No module named '__builtin__' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in File "/Users/amit/anaconda2/envs/py36/lib/python3.6/site-packages/pandas/__init__.py", line 23, in from pandas.compat.numpy import * File "/Users/amit/anaconda2/envs/py36/lib/python3.6/site-packages/pandas/compat/__init__.py", line 62, in import http.client as httplib ModuleNotFoundError: No module named 'http.client' 

Источник

No module named builtins

I’m trying to convert my .py script into an executable using py2exe. I’ve had a number of issues so far that have been largely addressed by the «options» in the setup file below. But now I have a problem that I have not been able to find a solution for, and wondering if others have had this same issue and fixed it. When I execute the setup file below using «python setup.py py2exe» it gives me an executable but when I run it, it complains «No module named builtins». The only other post I could find on this subject indicated that builtins is a python3 thing, but I’m running 2.7. Appreciate any advice or tips on this.

from distutils.core import setup import py2exe from distutils.filelist import findall import os import matplotlib matplotlibdatadir = matplotlib.get_data_path() matplotlibdata = findall(matplotlibdatadir) setup( console=['DET14.py'], options= < 'py2exe': < 'packages' : ['matplotlib', 'pytz'], 'dll_excludes':['MSVCP90.DLL', 'libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'libgdk_pixbuf-2.0-0.dll'], 'includes':['scipy.sparse.csgraph._validation', 'scipy.special._ufuncs_cxx'] >>, # data_files=matplotlibdata_files data_files=matplotlib.get_py2exe_datafiles() ) 

error message

Here is the full listing of what the error message looks like:

That stack trace points at a piece of code being packaged doing something interesting. It’d probably be worth looking at what, exactly, it’s up to.

Well, the odd thing about it is that the program executes perfeectly as a python script, yet it gives this error when run as an executable. Thus far problems of that kind have been addressed by modifying my setup file. I just can’t find anywhere what package I shoudl add (or other fix) in order to address this error.

I don’t doubt that there’s something py2exe is doing wrong, but you still need to look at the code that the exception is originating from to figure out what py2exe is doing wrong. Inspecting the code that can’t be run under py2exe is something of a prerequisite to figuring out why that code won’t run under py2exe, after all.

4 Answers 4

I also found using ‘pip install future’ resolved this issue

I hope this clarifies this for other users, like me who stumbled upon your question

Running pip install future fixed this error for me. For compatibility with Python2.7, the package future should be added to the install_requires in setup.py.

Note that nosetests also fails without matplotlib, but I’m not sure adding matplotlib as a dependency makes much sense.

I finally got this working. It turned out that I had some errors in the original setup file, some of which were outright dumb, and some simply reflected my lack of understanding of how the parameters of the setup command works. I will add that this latter class of errors was only resolved with some Sherlock Holmes-style sleuthing and plain old trial and error. By that I mean that I have still not found any documentation that calls out the meaning and usage of the parameters of the setup command. If anyone has that info and could pass it along that would be much appreciated.

With that as background, here is the answer:

There were 2 basic problems:

  1. The list of packages in the above setup file was woefully incomplete. I am still not certain that the rule is that you have to list every single package that your program relies upon, and some which it may rely upon that you didn’t know about (e.g. pytz). But when I did that, I had something at that point that I could eventually get to work.
  2. The error message in the above original question sort of looks like my program had a dependency on a thing called «patsy». This confused me because I had no idea what that was. It turns out that statsmodels (which is core to my project) has a dependency on patsy, so it needed to be included in the «packages» list.

Below is the setup file that ended up working. I hope this description of the logic behind the fix turns out to be helpful to others facing the same kind of problem.

from distutils.core import setup import py2exe from distutils.filelist import findall import os import matplotlib matplotlibdatadir = matplotlib.get_data_path() matplotlibdata = findall(matplotlibdatadir) setup( console=['DET14.py'], options= < 'py2exe': < 'packages' : ['matplotlib', 'pytz','easygui',\ 'statsmodels','pandas','patsy'], 'dll_excludes':['MSVCP90.DLL', 'libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'libgdk_pixbuf-2.0-0.dll'], 'includes':['scipy.sparse.csgraph._validation', 'scipy.special._ufuncs_cxx'] >>, data_files=matplotlib.get_py2exe_datafiles() ) 

Источник

Оцените статью