Error in ipython console "Exception [WinError 995] The I/O operation has been aborted" - windows

I have installed python 3.8.5 and in ipython 7.19.0 via Anaconda installer on Windows 10 machine and I get the following error in Ipython when I import keras and then run ls or any other commands.
It happens when I import other commands or run other commands. Can anybody propose any solution? Is this to do with latest python or Ipython? Or something else.
C:\Users\AA>ipython
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from keras.models import load_model
2021-01-06 10:36:43.729592: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
In [2]: ls
Unhandled exception in event loop:
File "C:\ProgramData\Anaconda3\lib\asyncio\proactor_events.py", line 768, in _loop_self_reading
f.result() # may raise
File "C:\ProgramData\Anaconda3\lib\asyncio\windows_events.py", line 808, in _poll
value = callback(transferred, key, ov)
File "C:\ProgramData\Anaconda3\lib\asyncio\windows_events.py", line 457, in finish_recv
raise ConnectionResetError(*exc.args)
Exception [WinError 995] The I/O operation has been aborted because of either a thread exit or an application request
Press ENTER to continue...

It seems to be a bug in the ipython prompt toolkit (version >= 3)
Try doing this for your environment:
conda install prompt-toolkit~=2.0
Generally we can fix this by doing something like this:
py -m pip install -U prompt-toolkit~=2.0
If that does not seem to work, there is an extensive discussion of the bug here with a few other solutions: https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1023#issue-534396318
(Discussed in this issue: https://github.com/jquast/blessed/issues/121)

According to this issue: https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1023
Upgrading python to at least 3.8.7 should fix this.

Related

Installing Octave Symbolic Package using SymPy (macOS) - Can't get SymPy to work

So, I've installed the Octave Symbolic Package from here:
https://sourceforge.net/p/octave/symbolic/ci/master/tree/
In the Octave command window I typed:
pkg install -forge symbolic
After the install I ran a test (as shown in link above) by typing:
pkg load symbolic
syms x
However, I got an following error with syms x.
Symbolic pkg v2.8.0: Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named sympy
error: Python cannot import SymPy: have you installed SymPy?
Try "sympref diagnose" for more information.
error: called from
assert_have_python_and_sympy at line 123 column 7
python_ipc_popen2 at line 79 column 5
python_ipc_driver at line 59 column 13
python_cmd at line 163 column 9
valid_sym_assumptions at line 38 column 10
assumptions at line 82 column 7
syms at line 97 column 13
Next, I visited the following site to install SymPy (which says to install Anaconda).
https://docs.sympy.org/latest/install.html#anaconda
So, then I go to the following site and download the graphical installer for macOS (Python 2.7 version).
https://www.anaconda.com/distribution/#download-section
Then I tested from the macOS terminal to see if Anaconda is installed using this command
conda --version
which returns conda 4.7.11.
I also typed
conda list
which returns (among a long list). sympy 1.4 py27_0.
So, it appears that SymPy is installed (at least at the terminal).
Next, I go back to the command line of Octave and typed:
sympref diagnose
Here is the output:
Symbolic package diagnostics
============================
Python and SymPy are needed for most features of the Symbolic package.
The Python interpreter is currently: "python".
Computers may have more than one Python interpreter installed. If you
need to, you can select a different one using the PYTHON environment
variable (see "help sympref"). For example, to use Python 3, try
setenv PYTHON python3
sympref reset
Attempting to run python -c "print(\"Python says hello\")"
status = 0
output = Python says hello
Good, Python ran correctly.
Python version
--------------
Let's check what version of Python we are calling...
Attempting to run python -c "import sys; print(sys.version)"
status = 0
output = 2.7.15 (default, Feb 5 2019, 12:31:36)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
SymPy Python Library
--------------------
SymPy is a Python library used by Symbolic for almost all features.
Attempting to run python -c "import sympy; print(sympy.__version__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named sympy
status = 1
output =
Unfortunately status was non-zero: probably Python cannot import sympy.
* Is there an error message above?
* Do you have SymPy installed? If not, please try to install it and
try again.
* If you do have SymPy installed, maybe it's installed for a different
Python interpreter than the one we found? Please try "setenv" as
described above to change your python interpreter.
Octave doesn't have access to SymPy.
Any idea what I did wrong?
Try running these in octave...
setenv PYTHON /usr/local/anaconda3/bin/python
pkg load symbolic
/usr/local/anaconda3/bin was where all my anaconda bits were installed,
including a version of python. Yours may differ.
sympref diagnose then passes for me.
You will have to do this every time you start 'octave' before using the symbolic package, but it should be safe.

Why is python's pip install behaving strangely in a script but fine in python prompt?

I'm trying to install a module from withing a python script using pip. Here is the contents of script.py:
#/usr/bin/python2.7
# I'm the file called `script.py`
import sys, importlib, pip
print(sys.version); print(sys.path) # For debugging
try:
importlib.import_module('docopt')
except ImportError:
pip.main(['install', '-U', 'docopt'])
finally:
globals()[pack] = importlib.import_module('docopt')
Runnting this script, e.g. using python2.7 script.py gives me:
$ python2.7 script.py
2.7.9 (default, Oct 3 2016, 17:42:24)
[GCC 4.3.2 20081105 (Red Hat 4.3.2-7)]
['/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/site-packages']
No module named docopt
Downloading/unpacking docopt
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement docopt
Cleaning up...
No distributions at all found for docopt
Storing debug log for failure in /root/.pip/pip.log
Traceback (most recent call last):
[...]
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named docopt
So problems with internet connection/ssl or something transport related. However, the same commands work perfectly fine in the python interactive interpreter, when I enter them by hand (copy&paste them):
$ python2.7
Python 2.7.9 (default, Oct 3 2016, 17:42:24)
[GCC 4.3.2 20081105 (Red Hat 4.3.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip, sys
>>> print(sys.path)
['/usr/lib/python27.zip', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/site-packages']
>>> pip.main(['install', '-U', 'docopt'])
Downloading/unpacking docopt
Downloading docopt-0.6.2.tar.gz
Running setup.py (path:/tmp/pip_build_root/docopt/setup.py) egg_info for package docopt
Installing collected packages: docopt
Running setup.py install for docopt
Successfully installed docopt
Cleaning up...
0
Again, the thing that weirds me out is, that it works interactively i.e. running python2.7 in the shell and then entering the very same code by hand. However, not when I run the script file with python2.7 script.py. So In one case, on the same machine, the same interpreter has internet access in the other case it does not.
I'm running out of troubleshooting ideas. I used the same machine and user to get above results. There is no python-startup file, so that is not making the commands magically work interactively. The contents of sys.path are the same in both cases. I'm not behind a proxy. Any ideas what could be missing in the script?
Cannot fetch index base URL https://pypi.python.org/simple/
indicates that for some reason your python interpreter cannot access to internet. There can be plenty of reasons for that. Do you use a HTTP proxy ?

Python 3 installation, additional to existing Python 2 on Windows: Fatal Python error: Py_Initialize: unable to load the file system codec

Sorry if this is a re-post. I have been searching for hours and there are a lot of similar problems, but they are not exactly the same as my issue.
I have been working with Python27 on my 64bit Windows for a while now and I would like to install Python 3 in parallel.
I downloaded and executed the installation .exe of Python 3.5 for 64bit Windows. The installation worked without any errors and added C:/Python35 to the Windows PATH variable.
However, when I click on python.exe in the directory C:\Python35, instead of launching a python 3.5 shell as it's supposed to do, it pops up a Window saying
Python has stopped working
Also there is a command shell saying:
Fatal Python error: Py_Initialize: unable to load the file system
codec File "C:\Python27\Lib\encodings__init__.py", line 123
raise CodecRegistryError,\
^ SyntaxError: invalid syntax
Current thread 0x00001ce0 (most recent call first):
So appearently Python 3.5 is using the Lib directory of Python 2.7. This is probably related to the PYTHONPATH variable that is set to
C:\Python27;C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk
When I change the PYHTONPATH variable to
C:\Python35;C:\Python35\Lib;C:\Python27\DLLs;C:\Python35\Lib\lib-tk
Python 3.5 works, but Python 2.7 throws the error above.
Is there any way to permanently define that the command "python3" uses one PYTHONPATH and the command "python2" uses another PYTHONPATH?
Copying python.exe and renaming it to python3.exe didn't help. Neither did uninstalling and installing Python 3.5 again.
I have a lot of old jupyter notebooks that are written in Python 2.7 and it would be great if I could continue to use them by choosing different kernels (see here).

Scipy installation windows 10

I have some difficulties trying to install Scipy for Python 3.5 on a Windows 10 machine and I hope I can find some help here. So here is what I have done so far.
I have downloaded the numpy+mkl for python 3.5 and 64bit version as well as the scipy0.18.1 for the same versions, from Gohlke's website
I installed the numpy+mkl whl with:
python -m pip install numpy-1.11.2+mkl-cp35-cp35m-win_amd64.whl
all goes well.
then I install the scipy package the same way like:
python -m pip install scipy-0.18.1-cp35-cp35m-win_amd64.whl
This also completes.
However, when I try to run python afterwards I get the following error:
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
File "C:\Python35\Lib\site-packages\scipy\io\__init__.py" , line 97, in <module>
File "C:\Python35\Lib\site-packages\scipy\io\matlab\__init__.py", line 13 in <module>
File "C:\Python35\Lib\site-packages\scipy\io\matlab\mio.py", line 8 in <module>
ImportError: No module named 'numpy'
I also get a pop-up that Python has stopped working.
I have tried a different order in which I installed the packages, but all lead to the error mentioned when Scipy is installed.
I also installed did this on a windows 7 machine and there it works.
Does anybody have any idea what causes this issue?
I also had some issues. So I just installed Anaconda3 insted of python directly.

ipython can't load a module which python does

I have recently updated to OSX El Capitain upgrading an exhisting working osx installation. Now I have a module, installed via pip on an anaconda distribution which is now broken. Or better the module can be correctly imported from python
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, Sep 15 2015, 14:29:08)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import MDSplus as mds
whereas it does not load on ipython, claiming not to finding a library.
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, Sep 15 2015, 14:29:08)
Type "copyright", "credits" or "license" for more information.
IPython 4.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
Using matplotlib backend: MacOSX
In [1]: import MDSplus as mds
Error importing MDSplus package: Error finding library: MdsShr
The library is correctly installed, it is listed in /etc/profile, it is located in /usr/local (so there should not be a problem with the new security system of OSX el Captain) and the python interpreted which is called via python or ipython is the same (Anaconda 2.3.0).
How can I diagnose which is the problem?
EDIT:
the solution proposed in https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/PEuOKEM5fdc does not worked for me. It does not seem to be an environment problem and the command
echo $DYLD_LIBRARY_PATH
points to the correct path
EDIT:
which -a ipython
ipython is /Users/vianello/anaconda/bin/ipython
which -a python
python is /Users/vianello/anaconda/bin/python
python is /usr/bin/python
>>> import sys
>>> for x in sys.path: print x
>>>/Users/vianello/anaconda/lib/python2.7/site-packages/pyhht-0.0.1-py2.7.egg
>>>/Users/vianello/anaconda/lib/python2.7/site-packages/MitDevices-0.3-py2.7.egg
>>>/Users/vianello/anaconda/lib/python2.7/site-packages/MDSplus-alpha_7.0.157-py2.7.egg
>>>//anaconda/lib/python2.7/site-packages/MDSplus-alpha_7.0.147-py2.7.egg/MDSplus
>>>/Users/vianello/anaconda/lib/python27.zip
>>>/Users/vianello/anaconda/lib/python2.7
>>>/Users/vianello/anaconda/lib/python2.7/plat-darwin
>>>/Users/vianello/anaconda/lib/python2.7/plat-mac
>>>/Users/vianello/anaconda/lib/python2.7/plat-mac/lib-scriptpackages
>>>/Users/vianello/anaconda/lib/python2.7/lib-tk
>>>/Users/vianello/anaconda/lib/python2.7/lib-old
>>>/Users/vianello/anaconda/lib/python2.7/lib-dynload
>>>/Users/vianello/anaconda/lib/python2.7/site-packages
>>>/Users/vianello/anaconda/lib/python2.7/site-packages/PIL
>>>/Users/vianello/anaconda/lib/python2.7/site-packages/Sphinx-1.3.1-py2.7.egg
>>>/Users/vianello/anaconda/lib/python2.7/site-packages/aeosa
>>>/Users/vianello/anaconda/lib/python2.7/site-packages/lmfit-0.8.3-py2.7.egg
>>>/Users/vianello/anaconda/lib/python2.7/site-packages/setuptools-18.3.2-py2.7.egg
>>>/Users/vianello/anaconda/lib/python2.7/site-packages/suds-0.4-py2.7.egg
in iPython the same give the results
/Users/vianello/anaconda/bin
/Users/vianello/anaconda/lib/python2.7/site-packages/pyhht-0.0.1-py2.7.egg
/Users/vianello/anaconda/lib/python2.7/site-packages/MitDevices-0.3-py2.7.egg
/Users/vianello/anaconda/lib/python2.7/site-packages/MDSplus-alpha_7.0.157-py2.7.egg
/Users/vianello/anaconda/lib/python27.zip
/Users/vianello/anaconda/lib/python2.7
/Users/vianello/anaconda/lib/python2.7/plat-darwin
/Users/vianello/anaconda/lib/python2.7/plat-mac
/Users/vianello/anaconda/lib/python2.7/plat-mac/lib-scriptpackages
/Users/vianello/anaconda/lib/python2.7/lib-tk
/Users/vianello/anaconda/lib/python2.7/lib-old
/Users/vianello/anaconda/lib/python2.7/lib-dynload
/Users/vianello/anaconda/lib/python2.7/site-packages/Sphinx-1.3.1-py2.7.egg
/Users/vianello/anaconda/lib/python2.7/site-packages/lmfit-0.8.3-py2.7.egg
/Users/vianello/anaconda/lib/python2.7/site-packages/setuptools-18.3.2-py2.7.egg
/Users/vianello/anaconda/lib/python2.7/site-packages/suds-0.4-py2.7.egg
/Users/vianello/anaconda/lib/python2.7/site-packages
/Users/vianello/anaconda/lib/python2.7/site-packages/PIL
/Users/vianello/anaconda/lib/python2.7/site-packages/aeosa
/Users/vianello/anaconda/lib/python2.7/site-packages/IPython/extensions
/Users/vianello/.ipython
Thus the MDSplus-alpha_7.0.157-py2.7.egg can be seen both from python and ipython
My first thought is that you are running afoul of the new Apple System Integrity Protection. iPython is launched using a shell script that loads via /bin/bash. That will result in your DYLD_LIBRARY_PATH environment variable being stripped when python launches. You can check this by importing os and then attempting to print the contents of os.environ["DYLD_LIBRARY_PATH"]. If that print throws an exception then you know what the problem is.
A simple fix that works for me is to edit the first line of the ipython script so that the #! calls your python binary directly rather than going via bash. This is not a long term solution as it will have to be redone each time ipython is updated until upstream changes (to be fair I'm not sure why bash is involved).
I have written a report on python and library paths at http://dmtn-001.lsst.io

Resources