pandas not works for django? - pandas

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.

Related

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!

Cannot find module PIL in Python

I am using:
Thonny Version 3.2.1
Python Version 3.7.0
PIP Version 19.2.3
Pillow Version 6.1.0
I am trying to import an image into my program and show it on the screen with the below code:
I get the error:
ModuleNotFoundError: No module named 'PIL'
backend.py, line 276
I believe the problem isn't my code, but instead an issue with the module Pillow not being found by Python?
Can anyone please help with a fix? I can clarify any info needed.
Additionally, I am new to Python and so go easy on me :-) Apologies if any of my terminology is incorrect.
I have tried:
1\ Removing PIL as per the install warning from Pillow (PIL Fork) install info. It was not present on my system. I did this through CMD.
2\ I always access CMD as the administrator.
3\ Updating all program versions above through CMD.
4\ Info I’ve found shows the above versions are compatible.
5\ Using the code help('modules') to show available modules, it does not show 'PIL' or 'Image', but does show 'pip'.
6\ Checked many forums for other fixes.
from PIL import Image
im = Image.open("JC.png")
im.show()

ModuleNotFoundError: No module named 'pandas.io' for json_normalize

Please read carefully. In my Python script I have the following:
import json
import pandas
from pandas.io.json import json_normalize
and it returns the following error:
from pandas.io.json import json_normalize ModuleNotFoundError: No
module named 'pandas.io'; 'pandas' is not a package
My steps:
I have uninstalled and installed Pandas
I have upgraded pip and pandas
I have installed io (pip install -U pandas.io)
I have installed data_reader and replaced the pandas.io.json part with that: from pandas_datareader import json_normalize
I have tried every solution I saw on stackoverflow and github and nothing worked. The only one I have not tried is installing Anaconda but it should work with what I tried before. Do you think it is a Windows setting things I must change?
PS: My Python version is 3.7.4
Try:
Go to ...\Lib\site-packages\pytrends on your local disk and open file request.py
Change
from pandas.io.json._normalize import nested_to_record
to
from pandas.io.json.normalize import nested_to_record
I had the same error, but it helped me.
also change
from pandas.io.json.normalize
to
from pandas.io.json._normalize
The cause of the problem was the fact that the python file had the name pandas. The filename was pandas.py. After renaming it, the code worked normally without errors.
i had same problem and i solve it b uninstalling extra python versions install on my windows.now i have only one python installed by anaconda,and everything is working perfectly

Using rPython import numpy with python 3.5

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)

import matplotlib.pyplot crashes on jupyter notebook

I have a jupyter notebook running on a remote cluster to which I have set up an ssh tunnel. Everything was working fine till today. Now everytime I do :
import matplotlib # This works
%matplotlib inline # This causes kernel to restart
import matplotlib.pyplot # This also causes the kernel to restart
Running a standalone ipython interpreter and doing :
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot ## Leads to Core dumped : Segementation Fault
Running the same on a python interpreter works fine.
Jupyter version : 4.1.1
Python version : 2.7.7
Any help would be much appreciated.
Thank You
Often, this kind of error seems to be related to the backend. Have you tried any other backends? Do these result in the same error? Like this we could narrow down the source of the error.
(I don't have a remote cluster, so I can not reproduce it.)
You can find available backends as described here.
I perhaps have the same problem but on my local machine. I got into jupyter3-qtconsole 4.2.1 with Python 3.4.5 and IPython 5.0.0. and enter
`%matplotlib
Using matplotlib backend: Qt4Agg`
the error message (shortened):
File "/usr/lib64/python3.4/site-packages/tornado/ioloop.py", line 603, in _run_callback
ret = callback()
and finally
from IPython.core.interactiveshell import NoOpContext as context
ImportError: cannot import name 'NoOpContext'
Same thing happens in a notebook but in a straightforward IPython terminal, everything runs OK
Hope this is helpful to someone