cannot import name 'multiarray' in numpy with python3 - python

I usually work with python 2.7 but this time i have to test a script in python3.
It is already installed on my computer, however when i start "python3", then go "import numpy", it show me "cannot import name 'multiarray'.
I even installed anaconda3 to test, but nothing happens
myName:~/anaconda3/bin$ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
I saw that it is looking in the lib/python2.7, but i cannot find what to do to get him search in the python3 library.
I already tried python -m pip install numpy, and tried to create a virtualenv in python3 but i still get the same error.
I cannot figure what to do. Can someone help me ?
I would like to add, i cannot start command with 'sudo' as i'm working on a client machine.
edit:
i tried #gehbiszumeis answer and got this:
myName:~ $ cd anaconda3/bin/
myName:~/anaconda3/bin $ source activate /home/myName/anaconda3
(base) myName:~/anaconda3/bin $ conda list numpy
# packages in environment at /home/myName/anaconda3:
#
# Name Version Build Channel
numpy 1.14.3 py36hcd700cb_1
numpy-base 1.14.3 py36h9be14a7_1
numpydoc 0.8.0 py36_0
(base) myName:~/anaconda3/bin $ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
I see there is numpy 36 installed when i type conda list numpy, but it seems not to work.. Did i miss something ?
edit2:
After #Pal Szabo method, i tested command python3 -m pip install --upgrade pip and got this error :
(env) (base) myName:~/anaconda3/bin $ python3 -m pip install --upgrade pip
Traceback (most recent call last):
File "/home/myName/anaconda3/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/home/myName/anaconda3/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/home/myName/anaconda3/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 4, in <module>
import locale
File "/home/myName/anaconda3/bin/env/lib/python3.6/locale.py", line 16, in <module>
import re
File "/home/myName/anaconda3/bin/env/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'`
It is a crazy mix between python3, python2.7 then again python3. I'm lost \o/
edit3:
I finally found my error.
It was a probleme with my PYTHONPATH, which was pointing somewhere where a .pth file was defined, with some hard link to python 2.7 libraries.
with a simple "unset PYTHONPATH" it works fine.
Thanks you all

I had the same problem, took me several hours to figure it out.
In my case, the PYTHONPATH was set to /usr/lib/python2.6/dist-packages/
changing it to /Users/xxx/miniconda3/lib/python3.7/site-packages/ resolved the issue.
Good luck.

Based what I can see from your code listing, it seems that the anaconda environment is not activated (this is usually indicated by the environments name in surrounding brackets () before the prompt). Because of that python3 tries to look for numpy and only finds the one you used for python 2.7 previously, which causes the error (see the python2.7 error messages)
Try
source activate <your-anaconda-environment>
Then your prompt should look like this
(<your-anaconda-environment>) myName:~/anaconda3/bin$
Numpy should be contained in the standard anaconda environment. Try then to check if numpy is installed within your environment with
conda list numpy
If there is no numpy listed, try to install it with pip as you wrote before.

If want to use python3, use pip3 instead of pip:
pip3 install numpy
You can try these too in terminal:
rm -Rf env
virtualenv -p python3 env
source env/bin/activate
python3 -m pip install --upgrade pip
pip3 install numpy
Also make sure that the first line of your script is
#!/usr/bin/python3
Don't write anything, even comments, before this.

I solved this problem changing the Python's version on VS Code. I was working with Python 3.7.4, now with the 3.7.8 one.
When I installed Numpy, it was stored in the folder of Python3.6. So I think that u could try to change the path or just change the Python's version

Related

Cannot import pywinauto on Windows 10

I installed pywinauto using pip install pywinauto.
OS: Windows 10
Python: 3.6.2
When I run python and try to import pywinauto, I get the error:
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pywinauto.application import Application
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\__init__.py", line 89, in <module>
from . import findwindows
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\findwindows.py", line 42, in <module>
from . import controls
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\controls\__init__.py", line 36, in <module>
from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\controls\uiawrapper.py", line 47, in <module>
from ..uia_defines import IUIA
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 181, in <module>
pattern_ids = _build_pattern_ids_dic()
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic
if hasattr(IUIA().ui_automation_client, cls_name):
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 50, in __call__
cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 60, in __init__
self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\client\_generate.py", line 118, in GetModule
mod = _CreateWrapper(tlib, pathname)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\client\_generate.py", line 183, in _CreateWrapper
generate_module(tlib, ofi, pathname)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\tools\tlbparser.py", line 750, in generate_module
gen.generate_code(list(items.values()), filename=pathname)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\tools\codegenerator.py", line 261, in generate_code
tlib_mtime = os.stat(self.filename).st_mtime
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'UIAutomationCore.dll'
Any ideas how to fix this?
I have the same issue today and fixed it by pip install comtypes==1.1.7.
It caused by comtypes library which release a new version 1.1.8 at Dec.26. Downgrade to previous version, it works well now.
It should be fixed in comtypes==1.1.9. Please check.
The problem was introduced in comtypes==1.1.8. My fault.
Try using a different version of python (e.g. 3.7.5 or 3.8):
https://github.com/pywinauto/pywinauto/issues/887
"Had the same issue with Python 3.7.6 and 3.8.1. Issue does not occur in 3.7.5 or 3.8.
I think this will be fixed in 3.8.2 ( but not sure yet)"
Try this, for me works fine
Install pywin32 from https://github.com/mhammond/pywin32/releases
pip install -U comtypes
pip install six
pip install Pillow
cd c:\windows\syswow64\
regsvr32 UIAutomationCore.dll
python
import pywinauto
#and the problem should be solved
I have Win10 and python 3.9..... i don't like Win10
Another thing could be your numpy library, uninstall it and install it again.
pip uninstall numpy
pip install numpy
Credits -> https://www.dll-files.com/download/65996a0afad353ec43ffe1ca69a2be88/uiautomationcore.dll.html?c=TTM2MGJJaHVRaEJkM1JyNDB3TDNwZz09

No module 'gi' and ImportError: The GTK3 backends require PyGObject error

I am trying to run some code on an AWS ec2 (ubuntu). When I comment out the portion that displays graphs from matplotlib, it runs fine. However, I want to view graphs.
When running the code, I get this error:
Traceback (most recent call last):
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 18, in <module>
import gi
ModuleNotFoundError: No module named 'gi'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "run.py", line 8, in <module>
from process_mask import ProcessMasks
File "/home/ubuntu/rPPG/process_mask.py", line 10, in <module>
matplotlib.use('GTK3Agg')
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py", line 307, in wrapper
return func(*args, **kwargs)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/__init__.py", line 1307, in use
switch_backend(name)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 221, in switch_backend
backend_mod = importlib.import_module(backend_name)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3agg.py", line 4, in <module>
from . import backend_agg, backend_cairo, backend_gtk3
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 20, in <module>
raise ImportError("The GTK3 backends require PyGObject")
ImportError: The GTK3 backends require PyGObject
I've been searching SO and other sources and have tried a lot of things including:
sudo apt-get install python3-gi
pip install vext
pip install vext.gi
sudo apt install python3-gi
pip3 install --user pgi
Also, this works:
$ /usr/bin/python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>>
but my actual code is in a virtual env with a bunch of dependencies, so this doesn't work with my actual code (/usr/bin/python run.py).
I ran into exact same issue, but after much efforts I managed to make TkAgg working (which was giving the import error for _tkagg). Little late, but someone might find it useful.
FWIW I resolved the issue as follows (to use TkAgg):
◉ Installed tk-dev from package manager
◉ Reinstalled python3-tk from package manager
◉ Rebuilt and reinstalled matplotlib from source
◉ (and of course setting TkAgg in matplotrc)
If you think you have tk-dev and python3-tk installed correctly, you need to rebuild and reinstall matplotlib, so that it generates _tkagg.py in your backends directory.
I'm using Python3.3 (numpy 1.7) on LM14. But I think it should work on Ubuntu/Python3.2
Thanks

Msys2 with python 3.8: ImportError: cannot import name 'open_code' from 'io'

NOTE: There have been several EDITs to the question, as per comments. They are indicated below, and separated by lines.
As of now, the only remaining issue seems to be that numpy cannot load, possibly (but not certainly) due to two alternative python 3.8 systems present.
I have updated my msys2 system a couple of months ago.
That apparently included an update from python 3.7 to 3.8, but which left me with two broken pythons: I can start python when it is 3.7, but there are no associated packages, and I cannot start python when it is 3.8, which is the version holding packages.
I do not know what went wrong with that, or what did I do wrong.
I just noticed this now with the first time I mean to use python again after the upgrade.
I will describe here a sequence of steps I followed and what I found.
I will post supporting code below for clarity.
I can start python, but pandas (e.g.) and many other packages are not found in python.
Checking further, /mingw64/lib/python3.7/site-packages is essentially empty (surely emptied when upgrading to 3.8).
Looking for the pandas package, I found I have one version installed.
The pandas version is for python 3.8, surely upgraded from 3.7.
I redirected PYTHONPATH from 3.7 to 3.8
Now I cannot even start python.
EDIT Now I can start python, with some misconfiguration issues (i.e., partially fixed).
Now the question is
How can I fix python3.8, which gives the error below?
ImportError: cannot import name 'open_code' from 'io' (unknown location)
How can I fix python3.8, which gives the problems below?
New problems:
5.1. I should have python pointing to 3.8, and also fix packages.
5.2. Some modules are not found, some other are.
Note: I don't know if Msys2 upgrade breaks python2-pyqt5 has anything to do with this.
Related:
https://github.com/tox-dev/tox/issues/1334
https://github.com/yan12125/python3-android/issues/19
https://python-forum.io/Thread-Fatal-Python-error-init-sys-streams-can-t-initialize-sys-standard-streams-Attribute
TL;DR: Supporting code
pandas not found
$ python
Python 3.7.4 (default, Jul 11 2019, 10:29:54)
[GCC 9.1.0] on msys
Type "help", "copyright", "credits" or "license" for more information.
Reading /home/user1/.pythonrc
readline is in /usr/lib/python3.7/lib-dynload/readline.cpython-37m.dll
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>>
pandas is actually installed
$ pacman -Sl | grep python | grep installed
mingw64 mingw-w64-x86_64-python 3.8.2-1 [installed: 3.8.1-1]
mingw64 mingw-w64-x86_64-python-apipkg 1.5-1 [installed]
...
mingw64 mingw-w64-x86_64-python-pandas 1.0.3-1 [installed: 1.0.1-1]
...
mingw64 mingw-w64-x86_64-python2-setuptools 44.1.0-1 [installed: 42.0.2-1]
msys python 3.7.4-1 [installed]
msys python2 2.7.17-1 [installed]
My pandas version is for python 3.8
$ pacman -Ql mingw-w64-x86_64-python-pandas | head -5
mingw-w64-x86_64-python-pandas /mingw64/
mingw-w64-x86_64-python-pandas /mingw64/lib/
mingw-w64-x86_64-python-pandas /mingw64/lib/python3.8/
mingw-w64-x86_64-python-pandas /mingw64/lib/python3.8/site-packages/
mingw-w64-x86_64-python-pandas /mingw64/lib/python3.8/site-packages/pandas-1.0.1-py3.8.egg-info/
I redirected PYTHONPATH from 3.7 to 3.8
Changed
export PYVERSION="3.7"
export PYTHONDIR2="${MINGW_HOME}/lib/python${PYVERSION}"
export PYTHONPATH="${PYTHONDIR2}:${PYTHONDIR2}/site-packages"
to
export PYVERSION="3.8"
...
Now I cannot even start python.
EDIT: Old problem:
$ python
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/io.py", line 54, in <module>
ImportError: cannot import name 'open_code' from 'io' (unknown location)
Aborted (core dumped)
New problems:
$ python --version
Python 3.7.4
$ type python
python is hashed (/usr/bin/python)
$ ls /usr/bin/python
/usr/bin/python
$ python3.8
Python 3.8.2 (default, Apr 9 2020, 13:17:39) [GCC 9.3.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Reading C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/home/user1/.pythonrc
Module readline not available.
Traceback (most recent call last):
File "C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/home/user1/.pythonrc", line 42, in <module>
del os, atexit, readline, rlcompleter, save_history, historyPath
NameError: name 'readline' is not defined
>>> import readline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'readline'
>>> import zipfile
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy: DLL load failed while importing _ctypes: No se puede encontrar el módulo especificado.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/numpy/core/__init__.py", line 106, in <module>
from . import _dtype_ctypes
File "C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/numpy/core/_dtype_ctypes.py", line 25, in <module>
import _ctypes
ImportError: DLL load failed while importing _ctypes: No se puede encontrar el módulo especificado.
>>> exit()
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'readline'
EDIT #2: Adding info as requested.
I just noticed I don't have pip. That matches the fact that I never installed any package with pip...
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/user1/OneDrive/Documents/soft-hard-ware/linux-ubuntu:/c/Users/user1/OneDrive/Documents/soft-hard-ware/linux-ubuntu/rsync:/c/Users/user1/Documents/appls_mydocs/science-math-visualization/gp524-win64-mingw_3/gnuplot/bin:/mingw64/bin
$ echo $PYTHONPATH
/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8:/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages
$ echo $PYTHONSTARTUP
/home/user1/.pythonrc
$ which python3.8
/mingw64/bin/python3.8
$ python3.8 -m pip freeze
C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/bin/python3.8.exe: No module named pip
$ python3.8 -c "import sys; print(sys.builtin_module_names)"
('_abc', '_ast', '_codecs', '_collections', '_functools', '_imp', '_io', '_locale', '_operator', '_signal', '_sre', '_stat', '_string', '_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref', '_winapi', 'atexit', 'builtins', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal', 'msvcrt', 'nt', 'sys', 'time', 'winreg', 'xxsubtype')
EDIT #3:
Posting as requested, plus additional info.
$ cat .pythonrc
import os
print( "Reading " + os.path.realpath(__file__) )
# enable syntax completion
try:
import readline
print( "readline is in " + readline.__file__ )
except ImportError:
print("Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
# From https://docs.python.org/2/tutorial/interactive.html
# Add auto-completion and a stored history file of commands to your Python
# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
# bound to the Esc key by default (you can change it - see readline docs).
#
# Store the file in ~/.pystartup, and set an environment variable to point
# to it: "export PYTHONSTARTUP=~/.pystartup" in bash.
import atexit
import os
#import readline
#import rlcompleter
historyPath = os.path.expanduser("~/.pyhistory")
def save_history(historyPath=historyPath):
import readline
readline.write_history_file(historyPath)
if os.path.exists(historyPath):
#import readline
readline.read_history_file(historyPath)
atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath
I don't see why which python3.8 and PYTHONPATH were out of sync:
$ cygpath -w $(which python3.8)
C:\Users\user1\Documents\appls_mydocs\PortableApps\MSYS2Portable\App\msys32\mingw64\bin\python3.8.exe
$ echo $PYTHONPATH
/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8:/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages
$ cygpath -w /c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8
C:\Users\user1\Documents\appls_mydocs\PortableApps\MSYS2Portable\App\msys32\mingw64\lib\python3.8
$ cygpath -w /c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages
C:\Users\user1\Documents\appls_mydocs\PortableApps\MSYS2Portable\App\msys32\mingw64\lib\python3.8\site-packages
$ which python
/usr/bin/python
I seem to have two incomplete/broken python installations (3.7, 3.8).
I don't know what led to an "incomplete" upgrade.
A couple of observations (see code below):
python points to 3.7
readline is available for 3.7 and not for 3.8.
I don't know why.
pandas (and many others) is available for 3.8 and not for 3.7.
Many of them won't import in 3.8 anyway, due to missing dependencies (which I guess are available in 3.7).
I don't know why.
python3.8 reports the location of .pythonrc in Windows format, while 3.7 reports it in Cygwin format.
Is that normal?
Removing PYTHONPATH does not help.
$ unset PYTHONPATH
$ python3.8
Python 3.8.2 (default, Apr 9 2020, 13:17:39) [GCC 9.3.0 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Reading C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/home/user1/.pythonrc
Module readline not available.
Traceback (most recent call last):
File "C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/home/user1/.pythonrc", line 42, in <module>
del os, atexit, readline, rlcompleter, save_history, historyPath
NameError: name 'readline' is not defined
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy: DLL load failed while importing _ctypes: No se puede encontrar el módulo especificado.
>>> exit()
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'readline'
$ python
Python 3.7.4 (default, Jul 11 2019, 10:29:54)
[GCC 9.1.0] on msys
Type "help", "copyright", "credits" or "license" for more information.
Reading /home/user1/.pythonrc
readline is in /usr/lib/python3.7/lib-dynload/readline.cpython-37m.dll
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>> exit()
EDIT #4:
I checked for all python packages, and I found something strange. It seems the basic python installation comprises two separate packages, one mingw64 and another msys.
I wouldn't know what does each one do.
$ pacman -Sl | grep "python" | grep "installed"
...
mingw64 mingw-w64-x86_64-python 3.8.2-2 [installed]
...
msys python 3.8.2-1 [installed: 3.7.4-1]
...
On one hand, there was a mismatch in installed versions mingw64 (3.8.2-2) vs msys (3.7.4-1).
On the other hand, the subversions available are not exactly the same for both (3.8.2-2) vs (3.8.2-1).
Anyway, I proceeded upgrading msys python, and this fixed things significantly.
$ pacman -S python
...
$ python
Python 3.8.2 (default, Apr 16 2020, 15:31:48)
[GCC 9.3.0] on msys
Type "help", "copyright", "credits" or "license" for more information.
Reading /home/user1/.pythonrc
Traceback (most recent call last):
File "/home/user1/.pythonrc", line 9, in <module>
import readline
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/readline.py", line 6, in <module>
from pyreadline.rlmain import Readline
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/pyreadline/__init__.py", line 12, in <module>
from . import logger, clipboard, lineeditor, modes, console
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/pyreadline/clipboard/__init__.py", line 13, in <module>
from .win32_clipboard import GetClipboardText, SetClipboardText
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/pyreadline/clipboard/win32_clipboard.py", line 37, in <module>
import ctypes.wintypes as wintypes
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/ctypes/wintypes.py", line 20, in <module>
class VARIANT_BOOL(ctypes._SimpleCData):
ValueError: _type_ 'v' not supported
Failed calling sys.__interactivehook__
Traceback (most recent call last):
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site.py", line 412, in register_readline
import readline
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/readline.py", line 6, in <module>
from pyreadline.rlmain import Readline
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/pyreadline/__init__.py", line 12, in <module>
from . import logger, clipboard, lineeditor, modes, console
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/pyreadline/clipboard/__init__.py", line 13, in <module>
from .win32_clipboard import GetClipboardText, SetClipboardText
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/pyreadline/clipboard/win32_clipboard.py", line 37, in <module>
import ctypes.wintypes as wintypes
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/ctypes/wintypes.py", line 20, in <module>
class VARIANT_BOOL(ctypes._SimpleCData):
ValueError: _type_ 'v' not supported
So I have readline in 3.8 now. But there is another issue that pops up during loading of .pythonrc.
Plus, there is a problem with numpy.
It does not stem from the python version (/usr/bin/python points now to 3.8).
$ python --version
Python 3.8.2
$ python
...
>>> import numpy
Traceback (most recent call last):
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/numpy/core/multiarray.py", line 14, in <module>
from . import overrides
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/c/Users/user1/Documents/appls_mydocs/PortableApps/MSYS2Portable/App/msys32/mingw64/lib/python3.8/site-packages/numpy/core/__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.8 from "/usr/bin/python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.3" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: No module named 'numpy.core._multiarray_umath'
EDIT #5
As per #a_guest suggestion, and pointing me to "ValueError: _type_ 'v' not supported" error after installing PyReadline, I removed pyreadline, and this problem is gone.
Now the only remaining issue seems to be that numpy cannot load, possibly (but not certainly) due to two alternative python 3.8 systems present.
So the questions now is: Msys2: Two python installations?
The ImportError: cannot import name 'open_code' from 'io' (unknown location) comes from the fact that there are two different versions of Python conflicting with each other. python still points to the old version 3.7 but PYTHONPATH got updated to point to the new 3.8 version. As the documentation of PYTHONPATH states, it becomes prepended to the module search path and hence shadows any builtin modules:
The default search path is installation dependent, but generally begins with prefix/lib/pythonversion (see PYTHONHOME above). It is always appended to PYTHONPATH.
You can reproduce that behavior by creating two different virtual environments and then start one while having PYTHONPATH point to the other. In the following I used Miniconda to create two different environments, py37 and py38, containing a 3.7 and 3.8 installation respectively.
(py37) user#pc:~$ python --version
Python 3.7.6
(py37) user#pc:~$ PYTHONPATH=~/miniconda3/envs/py38/lib/python3.8/ python
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
File "/home/user/miniconda3/envs/py38/lib/python3.8/io.py", line 54, in <module>
ImportError: cannot import name 'open_code' from 'io' (unknown location)
Aborted (core dumped)

Numpy import error Python3 on Raspberry Pi?

When I try to import numpy in Python3 i get an error.
I installed it via pip3 and it got installed succesfully.
sudo pip3 install numpy
Here is the error message when i try to import numpy:
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/numpy/core/__init__.py", line 16, in <module>
from . import multiarray
ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/local/lib/python3.5/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python3.5/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python3.5/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python3.5/dist-packages/numpy/core/__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: libf77blas.so.3: cannot open shared object file: No such file or directory
Moving my comment to an answer because it seemed helpful to a few users.
You are missing a core numpy dependency. Running
sudo apt-get install python-dev libatlas-base-dev
should fix the problem.
If that doesn't work, you can try installing RPi specific versions of numpy, see comments here.
I am going to add an answer as I don't have enough reputation to comment.
I had this issue on my Raspberry Pi 4.
In my case this was fixed simply by running this in the command line:
sudo apt-get install libatlas-base-dev
I thought initially I was missing a python module dependency, but this is a unix dependency, its shouldn't affect you python virtual environment
Installing libatlas-base-dev did not work for me.
Installing numpy==1.15.1 did.

How can I fix this pip error?

I am having some trouble understanding and fixing this issue in my python installation. Hopefully someone can help me wrap my head around this..?
Python itself runs (ie: the python command produces the expected REPL). When I try to use pip (pip search, pip install, ...) I get the following traceback (apparently there are core modules missing..?!):
Traceback (most recent call last):
File "/usr/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 26, in <module>
import zipfile
File "/usr/lib/python3.6/zipfile.py", line 13, in <module>
import shutil
File "/usr/lib/python3.6/shutil.py", line 13, in <module>
import tarfile
File "/usr/lib/python3.6/tarfile.py", line 48, in <module>
import struct
File "/usr/lib/python3.6/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'
But how can that be?
I've tried reinstalling python (through pacman) to no avail. Ditto for python-pip.
Perhaps the exception is misleading..?
What's with the core module struct importing a private version of itself that doesn't exist?! How could such an omission exist? Everyone's python 3.6 would be broken.. no?
sys.path = ['', '/code/scott/Py/Path', '/usr/lib/python3.6/Tools/scripts', '/usr/lib/python3.6/site-packages', '/usr/lib/python3.6', '/usr/lib/python3.6/lib/python36.zip', '/usr/lib/python3.6/lib/python3.6', '/usr/lib/python3.6/lib/python3.6/lib-dynload']
Python version:
Python 3.6.0 (default, Jan 16 2017, 12:12:55) [GCC 6.3.1 20170109] on
linux
Pip version: 9.0.1-2 (Built: 24/12/2016 06:47:25)
OS: Manjaro Linux (Arch Linux + KDE)
Kernel version: 4.9.9-1-MANJARO (from KInfocentre)
python and pip (python-pip) installed through pacman (arch package manager) via the commands:
sudo pacman -S python
sudo pacman -S python-pip
Ah! Importing struct from inside python produces the same error:
import struct
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'
...What information would be helpful? I can add to my question..

Categories

Resources