riginal error was: DLL load failed while importing _multiarray_umath - python

i got a something weird situation with import packages.
when i use numpy on Jupyter notebook, it's fine and my all source codes are run without problem
but if i use numpy on Visual Studio Code i got a something error.
ImportError: Unable to import required dependencies:
numpy:
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.8 from "C:\Users\Mohw-IN\anaconda3\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 while importing _multiarray_umath: The specified module cannot be used
다.
and i found something weird.
import os
print("PYTHONPATH:", os.environ.get('PYTHONPATH'))
---------------
PYTHONPATH: None
how can i do for use numpy in vscode?

It appears to be some issue related to path variable. This issue has been discussed on below github link.
https://github.com/numpy/numpy/issues/14770
To solve this, we need to add C:\Users<username>\Anaconda3\Library\bin" in your PATH user variable. Please replace "username" with actual value.
Now VS Code should work fine.

I don't even know what PATH is but i found an easier way to solve the problem
Install Anaconda
Open VScode from anaconda navigator
Done :)
You should be able to use Numpy now
If i open VScode from the desktop shortcut i still have the same problem
I don't now "why" it happens but i don't really care
hope this is usefull

In my case, it was a mismatch between the version of Numpy and Pandas (I had just upgraded to v1.4). Fix by upgrading numpy to sync it with Pandas:
In Anaconda/Miniconda:
conda update numpy
Or with pip:
pip install --upgrade numpy
Or this (very heavy-handed) approach which upgrades all packages:
conda install --update-all numpy

Open Anaconda and Launch Visual Studio. Now run the program.

Related

Python: No module named 'numpy'

I tried to import numpy but I received a ModuleNotFoundError: No module named 'numpy' error. Someone told me it could be because I didn't have numpy installed, but I already did.
upon installing numpy I got Requirement already satisfied: numpy in ./opt/anaconda3/lib/python3.8/site-packages.
which python returns /Users/MacBook/opt/anaconda3/bin/python. I am new at this, but I'm guessing the reason I got that error was because the files aren't in the same place? If so, how do I move it to the right place?
side note: I have a similar issue with matplotlib and this is running on VS code if that helps. Also I use spyder and I don't get the numpy nor the matplotlib error over there, but the error seems to be on VS code
Try uninstalling numpy and re-installing. You also try re-install anaconda. I had this same issue and that fixed it.
Anaconda installs its own conda environment to run python. Probably VS Code can't access. Try this command;
python -mpip install numpy
If your python file named numpy.py, you can get this error too.
If doesn't work maybe you can try to change the environment to Anaconda environment.
check this

Unable to run .bat file with python code: ImportError: Unable to import required dependencies: numpy:

I'm using Anaconda. I created an environment called ENGINEERING. In than environment I installed python 3.6, pandas 1.1.3, spyder 3.3.6, numpy 1.19.2, and many more. The base environment has these packages also but not necessarily the same version. Within the ENGINEERING env I created a python script in Spyder that runs without any issues when I run it in spyder. Then, I want to automate that script by creating a .bat file and then using that to automate via windows task scheduler. My .bat looks like this:
"C:\Users\alopo000\Anaconda3\envs\engineering\python.exe" "C:\Users\alopo000\Files\Python\Valid\Portf.py"
pause
when I run the .bat I get an error message:
ImportError: Unable to import required dependencies:
numpy:
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.6 from "C:\Users\alopo000\Anaconda3\envs\engineering\python.exe"
* The NumPy version is: "1.19.2"
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.
I've tried many things to fix this. I went to the website they suggested and couldn't find anything there. I uninstalled pandas and numpy and reinstall them again but still, same error. The one thing I haven't tried is to fix the VARIABLE PATHS, mostly because I've read in many places not to change those. I can change them if that's what it is, but I would like to understand first why it is not recommended. I read it can create issues with other versions of python but not sure if that's what it is.
Do I need to activate the environment in the .bat file? is the problem that the .bat file is trying to run it outside the environment? Any help would be appreciated.
You will need to upgrade/change your base Python & numpy version installations to match those specified (3.6, 1.19.2). I had the same issue and same situation as OP (write/dev program in a virtual Spyder environment "spyder-env", then automate .py file with WTS). I tried copying over & running the 'activate.bat' in the /scripts/ folder of the virtual environment but that didn't work. In my situation, my conda spyder-env was Python = 3.9.12 and numpy = 1.21.5.
I ended up upgrading my base global Python version (conda install) for Python which changed from 3.8.3 and did the same with numpy (had to downgrade). I'm not sure if this is exactly necessary, why this works, or if it may cause problems down the line (I was about to just re-install conda).
The appropriate .bat file should be something like this once you do that:
call "C:\Users\alopo000\Anaconda3\Scripts\activate.bat"
call "C:\Users\alopo000\Files\Python\Valid\Portf.py" %*
REM Uncomment below to debug
REM pause

Cloud Jupyter notebook Numpy .so file "failed to map segment from shared object"

I'm using the webbased Jupyter Notebook.
I've been getting this import error, so I checked the provided link, decided to reinstall Numpy.
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
* The Python version is: Python3.7 from "/usr/bin/python3"
* The NumPy version is: "1.20.3"
Original error was: /home/jupyter/.local/lib/python3.7/site-packages/numpy/core/_multiarray_umath.cpython-37m-x86_64-linux-gnu.so: failed to map segment from shared object
So I used pip uninstall numpy and then proceeded with y when asked.
How long does this usually take? It's been running for at least two hours by now. Is it supposed to take this long?
Is there an alternative solution for this?
I've tried sudo apt-get install libatlas-base-dev but this just returns a Syntax error.

Importing matplotlib.pyplot fails in PyCharm due to AttributeError: module 'PyQt5.QtGui' has no attribute 'QApplication'

I wanted to change my python compiler to "newer" one (within one project) and use some additional packages with conda. After the installation all my packages worked fine and I could use the console, however matplotlib.pyplot fails to import since then. And throws the following error: app = QtGui.QApplication([" "])
AttributeError: module 'PyQt5.QtGui' has no attribute 'QApplication'
After doing some research on this I found this one: link
It is suggesting to change inputhooks.py (on line 513 and change GUI_QT:enable_qt4 to GUI_QT: enable_qt5 4 to 5)
As it is a company machine, I can't have admin rights to overwrite things within PyCharm.
Can you recommend a better solution to avoid this?
Why is this popping up?
ErrorLogScreenshot
Also I tried to install the newer version of pyqt but that didn't fix the problem.
In the same time
Within pydev the interactiveshell.py fails as well. with the following error message:self.showtraceback(running_compiled_code=True)
TypeError: showtraceback() got an unexpected keyword argument 'running_compiled_code'
I understand it gets an argument which it is not expecting. I did some research on this one as well and some could fix it by deleting a stale a corresponding .pyc file (I couldn't find one at the same location as the initial file only interactiveshell.py)
Below this blog regarding pydev the conversation never went further
https://github.com/ipython/ipython/issues/10687
Is there a way to fix it?
I am kind of new to Python and don't quite understand the heart of it at this depth so any help is appreciated.
Thanks,
Anna
For anyone having the same issue, I have solved this problem by switching to qt and pyqt 4. To do so, follow the following procedure:
conda remove qt
conda install qt=4
conda install -c anaconda pyqt=4.11.4
conda install matplotlib --no-update-dependencies
If you are not using a virtual environment, you might also have to remove anaconda navigator before installing new packages:
conda uninstall anaconda-navigator
At the beginning of your program, switch matplotlib backend:
import matplotlib.pyplot as plt
plt.switch_backend('Qt4Agg')
Inspired by this solution.
After updating PyCharm all issues seem to have been resolved. (I was using versin 2017.1)
The show traceback error was due to pydev, and the new release fixes it.
As well as the GUI problem.
I was able to solve it by finding the file, and both messages disappeared, and matplotlib seems to work fine again.
Under this folder (I named my environment py35):
C:\Users\myusername\AppData\Local\Continuum\anaconda3\envs\py35\Lib\site-packages\IPython\core__pycache__
I found the file: interactiveshell.cpython-35.pyc and deleted it -
(This solves the problem only on Python 3.5)

How do I download and install Pandas and Numpy for PyPy in Windows

So I am using the Python interpreter PyPy as it makes my code run faster. However, everytime I try to run another code of mine, I get import error: No such module found. When I do a pip install pandas/numpy, it does not help as firstly the normal Python-2.7 folder already has it. And when I direct it to be installed directly to PyPy, the installation fails when it runs the setup.py file.
Could someone suggest another way in which I could get pandas and numpy to pypy? Thanks in advance!!
P.S. I have already tried: pypy setup.py install for pandas and numpy and it results in errors as well.
I'm not sure about the status of Pandas on Windows, but it looks like it doesn't work for shallow reasons and could be fixed. You should probably open an issue in PyPy's own tracker:
https://bitbucket.org/pypy/pypy/issues/
Be sure to mention it's on Windows, and include the complete copy of everything you typed and what is output.

Categories