MAC Python 3.8 IntelliJ error while importing panda module - python

In my Apple M1 chip machine, trying to import panda module in IntelliJ IDEA. while running this program its giving below error.
If I run the same program in command line, it works. Running into this problem while running in the IDE.
Any help to resolve this error message?
Code
import os
import pandas as pd
Remove my home dir from this output:
Error
Traceback (most recent call last):
File "panda-test01.py", line 9, in <module>
import pandas as pd
File "Library/Python/3.8/lib/python/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
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 "/Library/Developer/CommandLineTools/usr/bin/python3"
* The NumPy version is: "1.22.3"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: dlopen(Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: 'Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
Thanks

from your error message:
(mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
It's a little ambiguous as it could be interpreted either way round, but I think it means that IntelliJ is running using Rosetta2 in X86 mode, whereas the numpy/pandas installation the python PATH has is your arm version. (The alternative is the reverse of this, but this way round is more likely).
In order to run your program, you'll need to create a python environment which uses Rosetta2 and installs X86 binaries instead of arm. I've written about how to do this here as a reference for myself. Then IntelliJ should have a setting somewhere to specify the python environment to use for execution and debugging, you should set that environment/PATH to your new X86 environment.

Related

Can't get python scripts to work in Power BI [duplicate]

This question already has answers here:
How to run Python Script on powerBI
(3 answers)
Closed last year.
I currently have anaconda installed on my machine. I have a python script written which is working perfectly in Jupyter Notebook, the next step is I want to execute this script in Power BI to import data and pre-process the data.
I have adjusted the settings in powerBI (correctly I think):
Python Directory is set to C:\ProgramData\Anaconda3
Detected Python IDEs is set to Default OS program for .PY files
Can you provide a solution for the below error. I have spent hours trying to find something.
Error
Details: "ADO.NET: Python script error.
<pi>C:\PROGRAMDATA\ANACONDA3\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib
File "C:\PROGRAMDATA\ANACONDA3\lib\site-packages\pandas\__init__.py", line 16, in <module>
raise ImportError(
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:\PROGRAMDATA\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 could not be found.
</pi>"
If you need to run Python scripts in Power BI and have the Anaconda stack installed, it has to be activated before you can use it. Simply open the Anaconda Prompt or run conda activate on the cmd prompt. Then start PBIDesktop from within the activated environment like:
(base) C:\> "Program Files\Microsoft Power BI Desktop\bin\PBIDesktop.exe"
Make sure the Python home directory (Anaconda3) has been added to the PBIDesktop global options in the Python scripting section too.

Import Error when using VSCode with conda interpreter but not when importing in Conda

I'm trying to run a Python program in VSCode and it always stops in the first line
from sklearn.gaussian_process.kernels import WhiteKernel, RationalQuadratic, RBF, Matern, ExpSineSquared
The error it gives me is pretty big, I'll paste it at the end.
However, when when I open python in my conda terminal, I can import with no issues at all. Since I'm using the conda interpreter in VSCode, I don't understand what the issue is.
My Python version is 3.7.6, numpy 1.19.1, scipy 1.5.2, sklearn 0.23.2 and am working with Windows 10. I have already tried what the webpage mentioned suggested. And on the bottom left of VSCode it says that the interpreter is Python 3.7.6 64-bit ('base':conda).
Just tried, and I can't import numpy either, but can in conda with no problems. The python versions are the same. EDIT: The error message here asks me to be sure that the Numpy version is 1.18.1, instead of 1.19.1.
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:\Users\jdion\anaconda3\python.exe"
The NumPy version is: "1.19.1"
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.
File "C:\Users\jdion\OneDrive\Ambiente de Trabalho\Tese\Code\The Sea Exploration Problem _aux.py", line 13, in
from sklearn.gaussian_process.kernels import WhiteKernel, RationalQuadratic, RBF, Matern, ExpSineSquared
I uninstalled both conda and all my Python versions and when I reinstalled Python 3.7.9 and selected it as the interpreter in VSCode there were no more issues. I think the problem was having too many Python versions, anaconda, pip, and I was probably installing and removing things in the wrong places.

How to solve pandas import error in pycharm?

I've already install pandas from either the terminal and add pandas in pycharm project interpreter. However, every time I run a program which uses pandas it keeps reminding me there's an error.
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
Traceback (most recent call last):
File "/Users/Rabbit/PycharmProjects/NLP/review2vector.py", line 7, in <module>
from pandas import DataFrame
File "/Users/Rabbit/Library/Python/2.7/lib/python/site-packages/pandas/__init__.py", line 35, in <module>
"the C extensions first.".format(module))
ImportError: C extension: numpy.core.multiarray failed to import not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
I also followed this question's answer How to solve import error for pandas? But it does not work for me.
These issues can be easily avoided if you use a virtual environment to install and maintain your Python packages. Please refer to the link here for more information: LINK
The error message is telling you that numpy is not fully installed. There isn't enough information there to guess specifically what is wrong, but if I was troubleshooting I would use my package manager (pip probably) to uninstall and then re-install numpy and pandas. I would do numpy separately so that I could watch the messages. The numpy page says that they should have pre-compiled wheels available, so it just seems like a version mismatch.
Pycharm lets you install packages into a virtualenv easily and ensure that env is always activated when you open the pycharm terminal (great!) but it also makes it very hard to notice install errors.

I need Anaconda 32bit and 64bit

I currently develop in Pycharm v4 and use Anaconda 64bit. I now need to begin using http://www.zipline.io/ which only supports Anaconda 32bit. Is there a way to have both the 32 and 64 bit versions installed and just tell Pycharm which one to use for a specific project?
Pycharm supports the creation of virtualenv environments from within the IDE, perhaps something can be done in that way? I've never used virtual environments before. Or would it be possible to just install Anaconda 32bit into it's own folder, then tell Pycharm which to use for each project.
Any advice is appreciated.
I have installed Anaconda 32 bit in a separate folder and selected this version from within Pycharm settings for the interpreter. When trying to run a basic zipline project I get the following error:
"C:\...\Anaconda3 - 32bit\python.exe" "E:/Python Projects/ZiplineTesting/Main.py"
Traceback (most recent call last):
DLL load failed: %1 is not a valid Win32 application.
File "E:/Python Projects/ZiplineTesting/Main.py", line 1, in <module>
from zipline.api import order, record, symbol
File "C:\...\AppData\Roaming\Python\Python34\site-packages\zipline\__init__.py", line 25, in <module>
from . import data
File "C:\...\AppData\Roaming\Python\Python34\site-packages\zipline\data\__init__.py", line 1, in <module>
from . import loader
File "C:\...\AppData\Roaming\Python\Python34\site-packages\zipline\data\loader.py", line 25, in <module>
import pandas as pd
File "C:\...\AppData\Roaming\Python\Python34\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
ImportError: DLL load failed: %1 is not a valid Win32 application.
Process finished with exit code 1
It's worth noting that in my code, Pycharm has highlighted my import statement as having an error (with 'order' as well as 'record'). However there is nothing wrong with the import:
from zipline.api import order, record, symbol
The error is:
Unresolved reference 'order'
This inspection detects names that should resolve but dont.
Due to dynamic dispatch and duck typing, this is possible in a limited
but useful number of cases, Top-level and class-level items are supported
better than instance items.
Any ideas on what I might be doing incorrectly? I have tried uninstalling and reinstalling zipline which hasn't helped. It seems like there is some sort of conflict with my prior 64bit stuff with the new 32bit stuff.
In the "Settings" menu of PyCharm look for the "Project: [project name]" section. You can select the Python interpreter used for the project from there.
As long as the 32-bit version of Anaconda is installed to a separate location from the 64-bit version, there should be no problem.

How to use OpenCV in Python?

I have just installed OpenCV on my Windows 7 machine. As a result, I get a new directory:
C:\OpenCV2.2\Python2.7\Lib\site-packages
In this directory, I have two files: cv.lib and cv.pyd.
Then I try to use the opencv from Python. I do the following:
import sys
sys.path.append('C:\OpenCV2.2\Python2.7\Lib\site-packages')
import cv
As a result I get the following error message:
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
What am I doing wrong?
ADDED
As it was recommended here, I have copied content of C:\OpenCV2.0\Python2.6\Lib\site-packages to the C:\Python26\Lib\site-packages. It did not help.
ADDED 2
My environment variables have the following values:
Path=C:\Program Files\MiKTex\miktex\bin;C:\OpenCV2.2\bin;C:\Python26;
PYTHONPATH=C:\OpenCV2.2\Python2.7\Lib\site-packages
Do I need to change something? Do I need to add something?
ADDED 3
I think my question is general: How to use a library? Probably I need to find a *.ddl file somewhere? Then I need to use the name of the directory containing this file as a value to some environment variables? Or maybe I need to use sys.addpath? I also need to know how the way to call the library is related to the name of the file that contains the library.
ADDED 4
It is interesting that when I type import cv, I get:
ImportError: DLL load failed: The specified module could not be found.
But when I type import opencv I get:
ImportError: No module named opencv
ADDED 5
It has been suggested that I usthe e inconsistent version of python. In more details, OpenCV tries to use Python2.7 and I had Python2.6. So, I have installed Python 2.7. It makes difference. Now I do not have the old error message, but I have a new one:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: numpy.core.multiarray failed to import
ADDED 6
I have managed to resolve the problem by installing numpy. It took some time because I did not realized that there are different numpy installer corresponding to different versions of Python. Some details can be found in my answer to my own question (see bellow).
The problem was resolved. The following steps has been done:
A new version of python (version 2.7) has been installed.
After that I still was unable to run OpenCV because I had some problems with the numpy library.
I tired to install numpy but the installer did not see my new version of the Python.
I deleted the old version of Python as well as links to the old version in the Path system vatriable.
After that numpy installer was not able to finish the installation.
I have realized that I need to run another numpy installer that is associated with the Python 2.7. It can be found here.
Finally everything worked. I was able to "import cv".
I suspect you have the same problem I've run into. If you have a 64-bit version of Python, it cannot load 32-bit DLLs. OpenCV currently only ships 32-bit binaries. If you want 64-bit .pyd and .dll files, you have to compile them yourself. There are some instructions on the OpenCV Wiki, but it's not for the faint of heart. Expect to have a substantial time investment.
The easiest solution is to:
Uninstall 64-bit Python
Install a 32-bit distribution.
The PythonXY distribution includes pyopencv -- a good set of OpenCV hooks. The only limitation is that it's 32-bit, so don't make plans to process gigapixel astronomy data with it! ;)
If you must have the 64-bit version, follow these instructions to get it OpenCV to compile with Visual Studio 2010. There's a discussion on stackoverflow that describes building 64-bit apps with VC Express.
EDIT: OpenCV now ships with 64-bit Python binaries. The .dll files need to go somewhere in your path (I put them in the scripts folder), and the .pyd files go in your site-packages directory.
I had trouble interfacing OpenCV with Python, and I was looking all over the place for help. Here's what worked for me. I basically followed this post: http://opencvpython.blogspot.com/2012/05/install-opencv-in-windows-for-python.html. After downloading and extracting OpenCV 2.4.6, you basically get a folder called "opencv" with a bunch of stuff in it. Navigate to build->python->2.7. Inside, there is only one file called "cv2.pyd". I copied this file and pasted it in "python-2.7.5\Lib\site-packages". I'm actually using the Spyder IDE, and it works fine. In the python interpreter, typing in "import cv" worked for me.
Maybe you should edit your environment variable
right click on the "My Computer" or something like this, click on properties.
In the properties window click on the Advanced tab.
Then, the environment variables button.
Change the path.

Categories

Resources