Kernel Restarts upon failing(?) to import tensorflow - python

So I've recently updated my Anaconda environment, and now I can't import tensorflow anymore. Everytime I run a script containing it, the Spyder Console runs for a while, then just stops and resets to ln[1].
I tried to see how far the script compiles, and it does everything fine, until the import statement. Weirdly enough, the autocomplete still works for tf, which means that my installation should be fine. Reinstalling tensorflow also didn't do anything.
There are no error messages, because the compiler dies a silent death everytime I run the script. I've seen others describe a similar problem on a Jupyter, but their fixes didn't work. (Running the script without Spyder just freezes Python)
I'd greatly appreciate help

Ok so I did some black mathmagic and fixed it. What I did was reducing the tensorflow version via pip (to 1.14, but I don't think that matters) and then upgrading my entire conda set up again with conda update --all. I have no idea why, and the anaconda console screamed like it was tortured during the entire update, but now it works and I don't think I'll touch it again. If I see better fix, or if I encounter problems with this one, I'll update this post again.

Related

Environment issues with running Anaconda Python in VS Code

I am trying to learn Python and debug code for the first time in VS Code (latest edition). I have anaconda running and the code I have runs fine by itself but now I need to know how to update the code and debug it for the first time.
I keep getting the following error related to NumPy:
Exception has occurred: ImportError
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
The Python version is: Python3.7 from "C:\Miniconda2\envs\myproject_flask\python.exe"
The NumPy version is: "1.18.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: The specified module could not be found.
In the Miniconda path above the Python.exe is version 3.7.7. I tried to install NumPy like so in myproject directory:
(myproject_flask) c:\MyProject\source\MyProject.Flask>conda install numpy=1.18.5
I still get the same error when I go to F5 to debug and run to a breakpoint.
Need help with my environment.
I need to use VS Code in my Windows environment with Anaconda.
You should launch VS Code from Anaconda Navigator so that the environment is initialized.
When you have problems with importing the numpy C-extensions in Anaconda it's very likely that your virtual environment hasn't been activated. Having just Python on the path is not good enough. You also need access to the libraries. This is what the activation does.
When you are running/debugging code you should see a terminal open. You can tell from the prompt
(myproject_flask) C:\MyProject
that conda has been activated. Sometimes this just takes a bit too long for VSCode. So simply push the start button a second time.
Note that the Code Runner extension in VSCode is also known to cause this kind of problems.
However, I wonder why you are using Miniconda2 with Python3, although in general this should work.
I was getting the error even after adding all the anaconda paths, it was due to VScode running the code in the python debugger terminal which is not able to enter the conda environment.
This worked for me:
press ctrl+Shift+P > Type Terminal:Select Default profile > Select Command prompt
after this code ran in Command prompt by default, inside the environment.

ImportError loading spacy in jupyter notebook

I got a problem I can't seem to figure out. The first time I imported Spacy into a Jupyter notebook I had no problems. It just imported it as I expected.
The second time I tried to import it (using a different notebook) I got:
ImportError: cannot import name 'prefer_gpu' from 'thinc.api' (C:\python-environments\nlp\lib\site-packages\thinc\api.py)
So I tried to restart the kernel and tried it again (thinking that might be the issue). That did not solve it. Also trying to run the same cell that imported Spacy in the first notebook also throws the error now after it went well the first time.
It sounds like you have an old version of Thinc somewhere; try uninstalling and reinstalling Thinc.
Another thing to check is if you're running in the right Python environment. Sometimes Jupyter notebooks pull in a different environment than the one you're expecting in non-obvious ways. There was a thread in spaCy discussions about this recently. You can run this command to check which Python executable is being used in the notebook and make sure it's the one you think it is:
import sys
print(sys.executable)
I had a similar issue, followed the git hub link, created a new environment, and installed all required packages, and it resolved my issue. I'm using Visual code, so I had to install other dependencies since VC uses this as a conda environment as a base for my code implementation

Assertion Failed nbytes==sizeof (dummy) zeromq/src/signaler.cpp:402 Python.exe stopped working - Jupyter Notebook

I was successfully able to install Jupyter Notebook, with Anaconda. Everything was working fine, until suddenly one fine day I started to receive this message. Its happening when my Kernel is running for about continuous 1-1.5 hrs continuously.
I had gone through all possible solutions over Github, and did the following stuffs:
Uninstalled networkx
Turned off Firewall
Checked whether there is any anti-virus in my system, but there is none.
Since doing these did not fix the issue and ultimately I uninstalled zmq:
pip uninstall zmq and now I get this message:
Although I'm getting this message, but it seems that its not crashing automatically, I have to check for a longer time though. But I think that I'm doing something wrong, or something is there I'm not able to understand.
My OS is Windows 10, with only Windows Defender (Real-Time Protection) turned on, but previously also I had my Firewall and Defender both on, but never had this issue, suddenly I'm having all this problem. I didn't install anything, nothing.
I have found that if you change the port no. in signaler.cpp file, it may solve the issue, but at least if someone can help me locate the file atleast, I'm not able to find it under library folder in Anaconda packages.
P.S. If anyone can also tell me the significance of zmq library and whether it is important to keep it. Also I'm getting ssl error everytime I try to pip-install a module. So I have to write extra trusted link to do the installation.

IPython console in spyder extremely slow in Anaconda

I'm trying Anaconda/Spyder after using the standard python installation/IDLE for several years. The console (and variable explorer) becomes progressively slower during each work session, with every script and interactive command that I run. Eventually it takes minutes to get a response to simple commands like print, and then it stops responding completely and I shut it down. It's pretty disruptive to my work.
Mac OSX 10.13.6
conda version : 4.5.11
conda-build version : 3.15.1
python version : 3.7.0.final.0
qt 5.9.6
spyder 3.3.1
ipython 7.1.1
I do use matplotlib frequently. Whenever possible I use plt.ioff() at the beginning of a script and/or plt.close('all') at the end. Turning off matplotlib support completely in preferences doesn't help and it's not a permanent fix anyway. Python is not using anywhere near all my CPU or RAM.
As far as I've found out, the problem seems to be with the latest major release of the ipython kernel. Pinning the version of ipykernel to 4.10.0 solved it for me. To do so, add a line containing ipykernel 4.* to the file ~/anaconda3/conda-meta/pinned. Create the file if it does not exist yet. Then conda update ipykernel which will actually downgrade to 4.10.0. Worked for me!
you don't need to downgrade the entire spyder.
For me it worked with downgrading these two:
conda install ipython=6.4.0
conda install ipykernel=4.10.0
So this is not a totally satisfying solution but it seems to be a reasonable temporary fix. If you downgrade your spyder version to 3.1.X you will be able to use the python console rather than the Ipython console, and this seems to work for me. To do this just run:
conda install spyder=3.1
in the terminal while your environment of choice is active. This is not ideal, because the developers removed the python console for a specific reason as mentioned in this question, How to add python console in spyder.
Additionally downgrading this much may have unforeseen effects on other packages your code uses and may cause other issues but so far this is the only solution I was able to come up with.
#Sjoerd Thanks for your answer, this is what worked for me. To be still clearer, here's what I did in terminal on Anaconda 3 on High Sierra:
echo "ipykernel 4.10.0" >> ~/anaconda3/conda-meta/pinned
conda update anaconda
When I tried to update only ipykernel, I would have dependencies errors. By updating anaconda, everything is now up to date but ipykernel which is effectively at version 4.10.0. I didn't experience any hang since then.
#JJR4's answer didn't work for me (seems to work for others). Another workaround is to type %connect_info magic command into the IPython Spyder console which will display the JSON info to connect another console to the kernel.
The output of the magic command explains how to connect, but basically there are three options.
Paste the above JSON into a file, and connect with:
$> jupyter <app> --existing <file>
or, if you are local, you can connect with just:
$> jupyter <app> --existing <kernel>.json
or even just:
$> jupyter <app> --existing
if this is the most recent Jupyter kernel you have started.
I typically use qtconsole as the app. Once you enter your chosen connection method into the command line, a new console will open that is connected to the same kernel as the console in Spyder. For some reason, the new console does not lag even if the Spyder console does.
Enter everything in the new console, even runfile()
Hope this helps!
UPDATE:
Downgrading to ipykernel version 4.10 seems to solve the issue for me. Thanks to Carlos Cordoba - see GitHub conversation in link below.

Jupyter notebook python crash on Windows 10

I have spent a week searching and trying different solutions with no luck. I've seen several others having the same problems going back over a year.
The issue:
Windows 10 Pro build 15063.674
I'm using the latest Anaconda 5 build with Python 3.6.2 and all the packages are updated to most recent.
Running Jupyter Notebook, after some time, python will crash with a dialog "python has stopped working". This seems to happen after the notebook has been open for awhile, but I haven't been able to pinpoint an exact time. It's longer than 15 minutes but I've had it crash after a couple hours too.
The crash happens whether or not the notebook is in use, but most of the time, it's been while it's idle.
The console contains several lines like this:
Assertion failed: Connection reset by peer (bundled\zeromq\src\signaler.cpp:298)
I had been using everything with no issues, on a daily basis for months prior to this. I honestly have no idea what could have changed other than Windows Automatic updates.
What I've tried:
updating anaconda
updating all packages
updating python
full clean removal then reinstall of anaconda, python, and all packages
updating everything again
removing pyzmq and Jupyter then reinstalling
disabling Windows Defender
attempted to revert pyzmq on a long shot to 13.1.0 but the build failed
I've also tried using both conda and pip for installing/removing
Threads I've read:
https://github.com/zeromq/libzmq/issues/1808
https://github.com/ipython/ipython/issues/9975
https://github.com/ipython/ipython/issues/9236
https://github.com/zeromq/libzmq/issues/1108
https://github.com/zeromq/libzmq/issues/1573
Why python raised an AssertionError on some failed assumption in a ZeroMQ client?
Python.exe crashes while running Jupyter notebook sever
Why Does Jupyter Notebook Crashes?
Any suggestions on fixing this?
From the first issue thread you linked, it looks like this issue is with ZeroMQ, with little hope for resolution. One poster (UniversalAE) in that thread seemed to have success with replacing ZeroMQ with RabbitMQ. Absent an update to ZeroMQ that resolves this, or any specific requirement for ZeroMQ, I would advise doing the same, i.e. swap out ZeroMQ for RabbitMQ.
The solution was to uninstall a program called Networx.
I don't understand the error myself but the person I got the solution from linked this post: https://github.com/Microsoft/WSL/issues/1554#issuecomment-339743927

Categories