Can not import pandas in django project? [duplicate] - django

This question already has answers here:
Setting Matplotlib MPLCONFIGDIR: consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data
(2 answers)
Closed 6 years ago.
I am getting following error then I run application:
File "/var/opt/igp_modules/Mod51_LAM/mod51_LAM.py", line 235, in process
self.linesStructureCSV(inlist)
File "/var/opt/igp_modules/Mod51_LAM/mod51_LAM.py", line 610, in linesStructureCSV
from line_analysis import LAM
File "/var/opt/igp_modules/Mod51_LAM/line_analysis.py", line 2, in <module>
import pandas as pd
File "/usr/lib64/python2.6/site-packages/pandas/__init__.py", line 44, in <module>
from pandas.core.api import *
File "/usr/lib64/python2.6/site-packages/pandas/core/api.py", line 9, in <module>
from pandas.core.groupby import Grouper
File "/usr/lib64/python2.6/site-packages/pandas/core/groupby.py", line 17, in <module>
from pandas.core.frame import DataFrame
File "/usr/lib64/python2.6/site-packages/pandas/core/frame.py", line 41, in <module>
from pandas.core.series import Series
File "/usr/lib64/python2.6/site-packages/pandas/core/series.py", line 2909, in <module>
import pandas.tools.plotting as _gfx
File "/usr/lib64/python2.6/site-packages/pandas/tools/plotting.py", line 28, in <module>
import pandas.tseries.converter as conv
File "/usr/lib64/python2.6/site-packages/pandas/tseries/converter.py", line 7, in <module>
import matplotlib.units as units
File "/usr/lib64/python2.6/site-packages/matplotlib/__init__.py", line 709, in <module>
rcParams = rc_params()
File "/usr/lib64/python2.6/site-packages/matplotlib/__init__.py", line 627, in rc_params
fname = matplotlib_fname()
File "/usr/lib64/python2.6/site-packages/matplotlib/__init__.py", line 565, in matplotlib_fname
fname = os.path.join(get_configdir(), 'matplotlibrc')
File "/usr/lib64/python2.6/site-packages/matplotlib/__init__.py", line 240, in wrapper
ret = func(*args, **kwargs)
File "/usr/lib64/python2.6/site-packages/matplotlib/__init__.py", line 439, in _get_configdir
raise RuntimeError("Failed to create %s/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"%h)
RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data
but from terminal pandas is imported successfully.
[iv2user#develpoment-24 igp_modules]$ python manage.py shell
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import pandas
>>> import matplotlib
>>>
How can I fix this issue?
Server details:
OS: CentOS 6.8
Pandas: 0.17.1
Numpy: 1.11.1rc1

Read the last line of the error message:
RuntimeError: Failed to create /root/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data
matplotlib needs a writable location, and its trying to write to /root/.matplotlib and your django server probably doesn't have permission to write there because its not running as root (which is a good thing. Don't run as root just to defeat this).
You've not said how you've launched django (via apache? some other server?) but the fix would seem to be to set that environment variable to a location owned by the user that your django process runs as - possible user www or apache or something else.

Related

Oracle to Aurora - DMS - Failure

Need a Suggestion on the below. I was trying to do a DMS to aurora and i have installed python3.8.8. I have installed all required modules. Openssl is also installed.
When i trigger the script i encounter the below error.
Traceback (most recent call last): File "task_runner.py", line 2, in
import boto3 File "/usr/local/lib/python3.8/site-packages/boto3/init.py", line 16,
in
from boto3.session import Session File "/usr/local/lib/python3.8/site-packages/boto3/session.py", line 17, in
import botocore.session File "/usr/local/lib/python3.8/site-packages/botocore/session.py", line 30,
in
import botocore.credentials File "/usr/local/lib/python3.8/site-packages/botocore/credentials.py", line
34, in
from botocore.config import Config File "/usr/local/lib/python3.8/site-packages/botocore/config.py", line 16,
in
from botocore.endpoint import DEFAULT_TIMEOUT, MAX_POOL_CONNECTIONS File
"/usr/local/lib/python3.8/site-packages/botocore/endpoint.py", line
22, in
from botocore.awsrequest import create_request_object File "/usr/local/lib/python3.8/site-packages/botocore/awsrequest.py", line
26, in
import botocore.utils File "/usr/local/lib/python3.8/site-packages/botocore/utils.py", line 33,
in
import botocore.httpsession File "/usr/local/lib/python3.8/site-packages/botocore/httpsession.py", line
8, in
from urllib3.util.ssl_ import ( ImportError: cannot import name 'ssl' from 'urllib3.util.ssl_'
(/usr/local/lib/python3.8/site-packages/urllib3/util/ssl_.py)
I have tried changing the version of python as suggested in another post and also reinstalled awscli but nothing works. no matter what version of python used, i always end up with the same error.
Lastly, the server where am doing this doesnt have an internet connection.
Kindly suggest.
Cleaning up the entire Python setup and editing the Setup.dist to use SSL during build resolved the issue.

python3 django-admin syntax error

trying to learn python/django.
after installing all the bits and pieces getting this error (see list). please point into right direction. thank you!
$ django-admin startproject test1
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/bin/django-admin", line 11, in <module>
load_entry_point('Django==2.1', 'console_scripts', 'django-admin')()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2627, in load_entry_point
return ep.load()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2287, in load
return self.resolve()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2293, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 11, in <module>
from django.conf import settings
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/conf/__init__.py", line 18, in <module>
from django.utils.functional import LazyObject, empty
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/functional.py", line 12
return _curried_func(*args, *moreargs, **{**kwargs, **morekwargs})
^
SyntaxError: invalid syntax
Python 3.5.0a4 (v3.5.0a4:413e0e0004f4, Apr 19 2015, 14:18:20)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
2.1
You're using an alpha version of Python 3.5 - update your Python to the latest stable 3.5 release.

conda update --all = "ImportError: DLL load failed: %1 is not a valid Win32 application." when trying to import matplotlib.pyplot

I use the Python distribution. Python 2.7 x64 with Windows 7 SP1 x64 Ultimate.
After a conda update --all, whenever I try to import matplotlib.pyplot I get ImportError: DLL load failed: %1 is not a valid Win32 application.. Why?
Full error stack:
Traceback (most recent call last):
File "C:\svn\hw4\code\test_con.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 109, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\Anaconda\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "C:\Anaconda\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 17, in <module>
from .backend_qt5agg import NavigationToolbar2QTAgg
File "C:\Anaconda\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 18, in <module>
from .backend_qt5 import QtCore
File "C:\Anaconda\lib\site-packages\matplotlib\backends\backend_qt5.py", line 31, in <module>
from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
File "C:\Anaconda\lib\site-packages\matplotlib\backends\qt_compat.py", line 91, in <module>
from PyQt4 import QtCore, QtGui
ImportError: DLL load failed: %1 is not a valid Win32 application.
I had the same issue after running conda update anaconda. The solution that worked for me was to simply to download the latest windows installer, then uninstall and reinstall.
I suspect this is related to the pathname of your conda environment, as if you do a clean install anaconda now wants to live in C:\Users\yourname\AppData\Local\Continuum\Anaconda2, where previously it was just Anaconda (no 2). I suspect after running the upgrade scripts some things are pointing to the nonexistant (for you) "new" path.
I found that if I explicitly activate a conda environment with activate myenvname before running anything it works fine. Likewise if you you run from the "anaconda prompt" (which activates your default environment for you) it works fine. But to get my default environment to stay active from anywhere like its supposed to I had to reinstall.
Here is what worked for me:
Run conda update -f matplotlib (from the Anaconda command prompt)
This gave me a new error:
RuntimeError: module compiled against API version a but this version of numpy is 9
Traceback (most recent call last):
File "C:\svn\hw4\code\test_con.py", line 1, in <module>
import matplotlib.pyplot
File "C:\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "C:\Anaconda\lib\site-packages\matplotlib\colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "C:\Anaconda\lib\site-packages\matplotlib\artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "C:\Anaconda\lib\site-packages\matplotlib\transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: numpy.core.multiarray failed to import
Run conda update -f numpy
This gave me a new error:
Traceback (most recent call last):
File "C:\svn\hw4\code\test_con.py", line 1, in <module>
import matplotlib.pyplot
File "C:\Anaconda\lib\site-packages\matplotlib\pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "C:\Anaconda\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:\Anaconda\lib\site-packages\matplotlib\collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases
File "C:\Anaconda\lib\site-packages\matplotlib\backend_bases.py", line 56, in <module>
import matplotlib.textpath as textpath
File "C:\Anaconda\lib\site-packages\matplotlib\textpath.py", line 22, in <module>
from matplotlib.mathtext import MathTextParser
File "C:\Anaconda\lib\site-packages\matplotlib\mathtext.py", line 63, in <module>
import matplotlib._png as _png
ImportError: DLL load failed: The specified module could not be found.
Run conda install anaconda. This rolled your system back to a stable anaconda distribtution, and solved the issue. (I guess you could skip steps 1 and 2, but I don't feel like going through it again to confirm…)

Python import Error : cannot import module named _counter (which is a .so file)

I 'm using Jython to execute a python script connect_host.py which uses paramiko module to connect to a specified host.
paramiko module internally uses Crypto module, and Crypto.Util module uses Counter.py which in turn tries to import _counter,which is present in the same location Crypto.Util but as an .so file .
On execution, python throws the following error:
File "/location/helper/connect_host.py", line 3, in <module>
import paramiko
File "/python/modules/paramiko/__init__.py", line 69, in <module>
from transport import SecurityOptions, Transport
File "/python/modules/paramiko/transport.py", line 32, in <module>
from paramiko import util
File "/python/modules/paramiko/util.py", line 32, in <module>
from paramiko.common import *
File "/python/modules/paramiko/common.py", line 98, in <module>
from Crypto import Random
File "/python/modules/Crypto/Random/__init__.py", line 29, in <module>
from Crypto.Random import _UserFriendlyRNG
File "/python/modules/Crypto/Random/_UserFriendlyRNG.py", line 38, in <module>
from Crypto.Random.Fortuna import FortunaAccumulator
File "/python/modules/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in <module>
import FortunaGenerator
File "/python/modules/Crypto/Random/Fortuna/FortunaGenerator.py", line 35, in <module>
from Crypto.Util import Counter
File "/python/modules/Crypto/Util/Counter.py", line 29, in <module>
from Crypto.Util import _counter
ImportError: cannot import name _counter
How to make Jython load _counter module,which is a .so file??????
In this Python documentation it says:
Jython is an implementation of the Python language for the Java platform. Jython 2.7 implements the same language as CPython 2.7 ....
... Jython programs cannot currently use CPython extension modules written in C. These modules usually have files with the extension .so, .pyd or .dll.
If import _counter, is present in the same location as Crypto.Util but as an .so file, this would explain why it won't run from Jython.

import theano results in ImportError

I'm trying to use theano but I get an error when I import it.
I've installed cuda_6.5.14_linux_64.run, and passed all the recommended test in Chapter 6 of this NVIDIA PDF.
Ultimately I want to be able to install pylearn2, but I get the exact same error as below when I try to compile it.
EDIT1: My theanorc looks like:
[cuda]
root = /usr/local/cuda-6.5
[global]
device = gpu
floatX=float32
If I replace gpu with cpu, the command import theano succeeds.
Python 2.7.8 |Anaconda 1.9.0 (64-bit)| (default, Aug 21 2014, 18:22:21)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
Imported NumPy 1.9.1, SciPy 0.14.0, Matplotlib 1.3.1
Type "scientific" for more details.
>>> import theano
Using gpu device 0: GeForce GTX 750 Ti
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/g/anaconda/lib/python2.7/site-packages/theano/__init__.py", line 92, in <module>
theano.sandbox.cuda.tests.test_driver.test_nvidia_driver1()
File "/home/g/anaconda/lib/python2.7/site-packages/theano/sandbox/cuda/tests/test_driver.py", line 28, in test_nvidia_driver1
profile=False)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/compile/function.py", line 223, in function
profile=profile)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/compile/pfunc.py", line 512, in pfunc
on_unused_input=on_unused_input)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/compile/function_module.py", line 1312, in orig_function
defaults)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/compile/function_module.py", line 1181, in create
_fn, _i, _o = self.linker.make_thunk(input_storage=input_storage_lists)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/gof/link.py", line 434, in make_thunk
output_storage=output_storage)[:3]
File "/home/g/anaconda/lib/python2.7/site-packages/theano/gof/vm.py", line 847, in make_all
no_recycling))
File "/home/g/anaconda/lib/python2.7/site-packages/theano/sandbox/cuda/__init__.py", line 237, in make_thunk
compute_map, no_recycling)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/gof/op.py", line 606, in make_thunk
output_storage=node_output_storage)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/gof/cc.py", line 948, in make_thunk
keep_lock=keep_lock)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/gof/cc.py", line 891, in __compile__
keep_lock=keep_lock)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/gof/cc.py", line 1322, in cthunk_factory
key=key, fn=self.compile_cmodule_by_step, keep_lock=keep_lock)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/gof/cmodule.py", line 996, in module_from_key
module = next(compile_steps)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/gof/cc.py", line 1237, in compile_cmodule_by_step
preargs=preargs)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/sandbox/cuda/nvcc_compiler.py", line 444, in compile_str
return dlimport(lib_filename)
File "/home/g/anaconda/lib/python2.7/site-packages/theano/gof/cmodule.py", line 284, in dlimport
rval = __import__(module_name, {}, {}, [module_name])
ImportError: ('The following error happened while compiling the node', GpuCAReduce{add}{1}(<CudaNdarrayType(float32, vector)>), '\n', '/home/g/.theano/compiledir_Linux-3.11.0-26-generic-x86_64-with-debian-wheezy-sid-x86_64-2.7.8-64/tmpWYqQw5/7173b40d34b57da0645a57198c96dbcc.so: undefined symbol: __fatbinwrap_66_tmpxft_00004bf1_00000000_12_cuda_device_runtime_compute_50_cpp1_ii_5f6993ef', '[GpuCAReduce{add}{1}(<CudaNdarrayType(float32, vector)>)]')
I encountered exactly the same question.
My solution is to replace cuda-6.5 with cuda-5.5, and everything works fine.
We also saw this error. We found that putting /usr/local/cuda-6.5/bin in $PATH seemed to fix it (even with the root = ... line in .theanorc).