Using rPython import numpy with python 3.5 - numpy

My R version is 3.4.1, python version is 3.5.2 , and OS is Ubuntu 16.04.2
I have set RPYTHON_PYTHON_VERSION=3.5 when installing rPython, which is my default python version for rPython.
♥ python.exec('import sys')
♥ python.exec('print(sys.version)')
3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609]
When I import numpy through rPython (there is no issue with using import numpy in python 3.5, everything works fine.), I got this:
♥ python.exec('import numpy')
Error in python.exec("import numpy") :
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: /usr/local/lib/python3.5/dist-packages/numpy/core/multiarray.cpython-35m-x86_64-linux-gnu.so: undefined symbol: PyType_GenericNew
However, if I set RPYTHON_PYTHON_VERSION=2 and reinstall rPython, the import numpy works. How can I successfully import numpy under rPython with python 3.5?

First off, can you import any packages into python 3.5.3 from R/rPython?
I am also having this problem. The error I get is exactly the same as the posters (numpy won't load). I later found that I cannot import any packages. I can however import packages in python 2.7.13 and python 3.5.3 (just not through R/rPython). This leads me to believe that this is an 'rPython' R package error. Here are the things that I have tried to do to fix this:
1) I have tried installing/reinstalling the R package rPython to use either python 2.7.13 or python 3.5.3. I could connect R to python 2.7.13 via reinstall of the rPython package:
install.packages("rPython",lib= "home/myusername/R/x86_64-pc-linux-gnu-library/3.4", configure.vars= "RPYTHON_PYTHON_VERSION=2")
Using "RPYTHON_PYTHON_VERSION=3" during install similarly allowed me to connect R with python 3.5.3. I could call "import numpy" from R when rPython was connected to python 2.7.13, but not when connected with 3.5.3.
2) I have tracked down all numpy and scipy's which had been previously installed and uninstalled them. I had several copies of each for both python 2.7.13 and python 3.5.3. Reinstalling using pip and pip3 did not fix the problem (I restarted R beforehand to be safe).
From both accounts this seems to be a problem with the R package 'rPython'. You could try the newer 'reticulate' package from R, and see if this works better for you. However, I have not been able to get parallel threads to work when using reticulate to connect R with python, and this is unfortunately what I need to do. Threading did however work perfectly when using 'rPython', but the package I need requires python 3+. I will keep troubleshooting and update this post if I am able to solve it. In the meantime, give 'reticulate' a shot, it is a very neat package.
EDIT
I was able to load numpy from python 3.5.3 in R using the 'reticulate' package.
EDIT2 For those who find this post in the future, the only solution I could find to use python3 code with multithreading from R was to call python files with system(python3 "path_to_python_script" arg1 arg2 arg3)

Related

Unable to import required dependencies: numpy

I'm trying to build a visual dashboard in VS Code using dash. But I can't get past this error I'm getting:
Original error was: DLL load failed: The specified module could not be
found. File "C:\Users\ko14Z57\plots.py", line 1, in
import pandas as pd
Exception has occurred: ImportError Unable to import required
dependencies: numpy:
I'm using python 3.6.13 but I've tried this with python 3.9 and 3.8. I also tried installing\uninstalling numpy and pandas. I'm using Anaconda for my package management. Any help would be really appreciated!
in vscode from view>command palette write 'select your default profile' the select 'Command Prompt' or 'cmd.exe'
Assuming that Bas may be right, and you're missing the Microsoft C++ compiler. Try installing Microsoft's "C/C++ Extension Pack": https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack . You can find it in VSCode by clicking the extensions icon at the left side and searching "cpptools".
Since I'm using conda, I updated conda and then updated all of my packages and that worked.
conda update conda
conda update --all
Note: I'm on Python 3.9 on a Windows machine.
Probably unnecessary, but I also added the interpreter path to my launch.json file:
"python": "C:\\Users\\<username>\\Anaconda3\\python.exe"

Pandas runtime error /anaconda3/lib/python3.8/site-packages/pandas/__init__.py", line 13 missing_dependencies

I need to do some stuff using pandas.
Inside my python file, I wrote this:
sys.path.append("/home/user0/anaconda3/lib/python3.8/site-packages")
import pandas as pd
When I run the program,I get this:
File "/home/user0/anaconda3/lib/python3.8/site-packages/pandas/__init__.py", line 13
missing_dependencies.append(f"{dependency}: {e}")
^
SyntaxError: invalid syntax
I installed Anaconda, and I can verify that pandas is available.
My working environment is inside Anaconda's virtual environment, where python version is 3.8.
When I "conda deactivate", my python version is 2.7.
When I login to the server, my Anaconda env is already activated, and I get a prompt like this:
(base) user0#optiplex:~$
"conda list" tells me my pandas version is 1.0.5, and numpy is 1.18.5.
I have already updated Anaconda using "conda update --all". No improvement.
Some diagnostics:
(base) user0#optiplex:~$ python
Python 3.8.3 (default, Jul 2 2020, 16:21:59)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/home/user0/anaconda3/bin/python'
>>> import sys
>>> sys.path
['', '/home/user0/anaconda3/lib/python38.zip', '/home/user0/anaconda3/lib/python3.8',
'/home/user0/anaconda3/lib/python3.8/lib-dynload',
'/home/user0/anaconda3/lib/python3.8/site-packages']
>>>
Someone please give me some hints.
Thank you.
First, I tried different keywords and googled, and landed on exactly this item in stack overflow!
It mentions may be there is python version mismatch.
https://ja.stackoverflow.com/questions/67370/import-pandas-%E3%81%A7-pandas-init-py-%E3%81%AB%E5%AF%BE%E3%81%97%E3%81%A6-syntaxerror-%E3%81%8C%E3%81%A7%E3%81%BE%E3%81%99
I was running my code inside another program that uses python 2.x internally, so it could be the case, I don't know. I don't know much about python, specially working env setup, so I cannot make anymore comments.
Second, I ran the code once again, right after the first error, and the second time, the program worked. I don't know what to make of it either.
BTW, AtanuCSE, thank you for formatting my question!

Error in Power BI while importing pandas library in python scrip

Below are the mentioned error while importing pandas library in Power BI in python script.
Details: "ADO.NET: Python script error.
C:\USERS\YADAVP\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:\USERS\YADAVP\ANACONDA3\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
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.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\USERS\YADAVP\ANACONDA3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" 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: DLL load failed: The specified module could not be found.
What is the resolution to sort this kind of error in Power BI?
Forget Anaconda and use WinPython.
I tried Anaconda for days with all the workarounds available in StackOverflow and other forums, and they took me nowhere.
Then I tried WinPython, and it worked immediately. Of course, you will need to change the PowerBI options accordingly.
To install WinPython: https://github.com/winpython/winpython
To change the detected Python home directory: https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-python-scripts#enable-python-scripting
If you consider my answer, you won't need to downgrade Python, PBI, or anything else.
I had the same error. Unfortunately, PowerBI wont work with Jupyter Notebook Python.
So you have to install a "normal" Python: https://www.python.org/downloads/
And configure the Python you want to use in PowerBI and install your needed Python libraries via pip
Edit: Please use Python 3.8 because 3.9 doesnt support NumPy for now

pandas not works for django?

I saw the first rocket.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world.")
'Hello, world.' it's ok!
also 'python manage.py migrate' ok.
But when I import pandas...
(import only and no use.)
from django.http import HttpResponse
import pandas as pd
def index(request):
return HttpResponse("Hello, world.")
Browser thinks forever.
How can I fix this issue?
my environment
OS: CentOS Linux release 7.7.1908 (Core)
Pandas: 0.19.2
Apache: 2.4.6 (CentOS)
Django: 2.1
Browser: Google Chrome 76.0.3809.132
# python --version
Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
simply, Anaconda is older?
Please let me know if there is any missing information.
Progress after that. Tried "Panda" update.
#Conda installs panda
I was able to clear the browser thinking during the import error.
I will re-install Newest Anaconda.
(_mysql_exceptions.OperationalError) (2006, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)") (Background on this error at: sqlalche.me/e/e3q8)
Currently, if you don't use django, you can execute SQL from py file to MySQL.
The situation has improved. It hasn't been resolved yet, but the error has changed this morning. I will challenge again when the work is over.
Settled! I think anaconda was old. Speaking of which, it took about two years to build a VPS, and anaconda was the version at that time.

Enthought Canopy Pandas not installing

Using Enthought Canopy; the following command import pandas produces this error message:
ImportError: C extension: hashtable not built. If you want to import pandas
from the source directory, you may need to run 'python setup.py build_ext --
inplace' to build the C extensions first.
Which I understand means that the package hasn't been built with it's C dependencies? I thought Canopy's environment handled module installations, I have tried removing, and updating Pandas with no luck.
Does anyone know how to correctly use Pandas in Enthought Canopy?
Forcing a reinstallation of Pandas and its dependencies with enpkg pandas --forceall run from a Canopy Terminal/Command Prompt seems to have fixed the problem.