I'm using Spyder to do some small projects with Keras, and every now and then (I haven't pinned down what it is in the code that makes it appear) I get this message:
File "~/.local/lib/python3.5/site-packages/google/protobuf/descriptor_pb2.py", line 1771, in <module>
__module__ = 'google.protobuf.descriptor_pb2'
TypeError: A Message class can only inherit from Message
Weirdly, this exception is not raised if I execute the program outside of Spyder, using the terminal. I've looked around and I have found no one who has encountered this error while using Keras.
Restarting Spyder makes it go away, but it's frustrating. What could be causing it?
I had the same problem with Spyder, which happened when it was trying to reload modules that were already loaded. I solved it by disabling the UMR (User Module Reloader) option in "preferences -> python interpreter" .
Ok, I found the cause: interrupting the execution before Keras fully loads.
As said before restarting Spyder (or just the console) solves it.
Restarting Sypder works or run your script using console only.
Don't forget to use at the top:
from google.cloud import bigquery
from google.oauth2 import service_account
from google.auth.transport import requests
Related
I was making a program using pywhatkit to send WhatsApp messages. However, when trying to import pywhatkit, the following exception is raised:
(Sorry, I was not able to copy the error message.)
Can anyone tell me why this is happening?
One of the dependencies of pywhatkit is the pyautogui module (see here for what pyautogui is). REPL.it runs on Linux, a Unix-like OS; on Unix, pyautogui requires Xlib (hence, Xlib.error.XauthError). On importing pywhatkit, Xlib attempted to open the .Xauthority file, but failed to do so, in this case because the file does not exist. I believe this behavior has to do with REPL.it itself, i.e., there's nothing you can do about it.
For background on what the .Xauthority file is, refer to this AskUbuntu question.
I am trying to run a basic sqlAlchemy program and trying to import the module as shown in block 1 of the picture.
Block 2 shows that the code gives me the error that the module is missing.
However if you see block 4 ( the second part of split-ted console), you would see that the sqlAlchemy module is very much installed in the environment.
Also note from block 3 that I am using a virtual environment which is active as the console suggests.
Any help in explaining the reason why this is happening would be highly appreciated.
If you look at your block 4 you will notice you are using an Anaconda install for that import while block 3 shows you're using a virtual environment when trying to execute the code. I suspect that if you open the Python interpreter as specified when executing your script (/Users/.../Desktop/PyProject/venv/Scripts/python.exe) and then try import sqlalchemy at the REPL then the import won't work. Or put another way, the python you manually launched may not be pointing to the one set as the interpreter in VS Code.
I am getting this error in my Anaconda just after i install opencv in it. I know its a repeated question in StackOverflow but i tried all the fixes that are previously given here and nothing changes.
I tried this fix it solves the problem but not permanently. It works only when i run the command on terminal it works fine then but as soon after i close the terminal and starts it again and run program again error starts to appear again. Is there any permanent solution??
Try this:
export GIO_EXTRA_MODULES=/usr/lib/x86_64-linux-gnu/gio/modules/
I am fairly new to programming in python. I installed anaconda and am running iPython (the Jupyter qtconsole) v.4.3.0 and python v.3.6 on a Mac. Currently, I am trying to import a module with functions located in my home directory.
I have looked at stackoverflow and python documentation and found that it could be done with:
%run "Users/myUser/python_functions.py"
or
import python_functions
However, when I try both of these approaches, I get prompted to overwrite the file that I am running or importing:
File `python_functions.py` exists. Overwrite (y/[N])?
This is changing the previous file and not getting the functions I want to be imported.
What may explain this, and what can I do to import my module?
this is wrong but leaving it up for shame
import on ubuntu (and I'm guessing many other unix-like OSs including Mac) is a utility that saves any visible window on an X server and outputs it as an image file. You can capture a single window, the entire screen, or any rectangular portion of the screen.
My guess if you are running the import command in your console, and it's about to take a screenshot and save it over an existing file - python_functions
Before you the use the python import command, start a python interpreter:
$ python
>>>import yourfile
edit: on re-reading your question, I'm not so sure about my guess anymore, but leaving it up until you tell me I'm wrong :)
Running Jupyter qtconsole as an interpreter is likely causing the problem in this scenario. Instead using a IDE or command line interpreter will resolve it .
Since anaconda was installed, trying it with the IDE Spyder executes the code just fine without the overwrite prompt. It works on others (e.g PyCharm, Rodeo, etc.) as well.
I have a weird bug in my project that uses PySide for its Qt GUI, and in response I'm trying to test with simpler code that sets up the environment.
Here is the code I am testing with: https://stackoverflow.com/a/6906552/130164
When I launch that from my shell (python test.py), it works perfectly. However, when I run that script in Spyder, I get the following error:
Traceback (most recent call last):
File "/home/test/Desktop/test/test.py", line 31, in <module>
app = QtGui.QApplication(sys.argv)
RuntimeError: A QApplication instance already exists.
If it helps, I also get the following warning:
/usr/lib/pymodules/python2.6/matplotlib/__init__.py:835: UserWarning: This call to matplotlib.use() has no effect
because the the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
Why does that code work when launched from my shell but not from Spyder?
Update: Mata answered that the problem happens because Spyder uses Qt, which makes sense. For now, I've set up execution in Spyder using the "Execute in an external system terminal" option, which doesn't cause errors but doesn't allow debugging, either. Does Spyder have any built-in workarounds to this?
As Spyder also is a Qt application, it starts it's own QApplication. In the same process only one QApplication can exist, that's why you get the first error.
Sypder also uses matplotlib, and probably, therfore it already will have imported some of the mentioned modules, so that's why you get the second error.
So when usin it like that, you can't create your own QApplication or call matplotlib.use(). Or maybe it will work if you wrap these calls in try/except.
I have the same problem, and somewhere on stackoverflow was a solution.
Instead of
qApp = QtGui.QApplication(sys.argv)
Use
qApp = QtGui.QApplication.instance()
if qApp is None:
qApp = QtGui.QApplication(sys.argv)
It won't work in Spyder if you try to launch the application into an interactive console because that console is specially configured to import several scientific libraries, automatically show() matplotlib figures, and a few other details. Type scientific at the Spyder console prompt for more details. The result is effectively that a Qt application event loop is already running there.
To get your application to run inside of Spyder:
Make sure Spyder is configured to open external consoles with PySide and not PyQt. This can be set from Tools>Preferences>Console>External modules>Qt-Python bindings library selection.
With your script active in the editor, hit F6 to open the Run Settings dialog. Select the "Execute in a new dedicated Python interpreter" radio button instead of executing in the current interactive interpreter. Click OK. Now run the script by hitting F5. Debug the script by hitting Ctrl+F5.
The official Spyder wiki has a page on the subject: https://github.com/spyder-ide/spyder/wiki/How-to-run-PyQt-applications-within-Spyder. The gist of it is:
Important Note: Before running a PyQt application in Spyder, you need to change your Graphics backend to Automatic. You can do that by going to
Tools > Preferences > IPython Console > Graphics
After that, please restart your console kernels or Spyder itself for this change to take effect.
There's an explantion at the end:
The most common problem when running a PyQt application multiple times inside Spyder is that a QApplication instance remains in the namespace of the IPython console kernel after the first run. In other words, when you try to re-run your application, you already have a QApplication instance initialized.
Trying to remove that instance will probably cause your program to get stuck in a blocking while-loop, as suggested here, and using sys.exit() doesn't help since it's the same as trying to exit Python (and hence the IPython console).
A suggested solution is doing something like what #mata suggsets.