Python module issue - python

I have a shared hosting environment on Bluehost. I am running a custom installation of python(+ django) with a few installed modules. All has been working, until yesterday a change was made on the server(I assume) which gave me this django error:
... File "/****/****/.local/lib/python/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/****/****/.local/lib/python/django/db/backends/mysql/base.py", line 14, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient_r.so.16: cannot open shared object file: No such file or directory
Of course, Bluehost support is not too helpful. They advised that 1) I use the default python install, because that has MySQLdb installed already. Or that 2) I somehow import the MySQLdb package installed on the default python, from my python(dont know if this can even be done). I am concerned that if I use the default install I wont have permission to install my other packages.
Does anybody have any ideas how to get back to a working state, with as little infrastructure changes as possible?

I think you upgraded your OS installation which in turn upgraded libmysqlclient and broke native extension. What you can do is reinstall libmysqlclient16 again (how to do it depends your particular OS) and that should fix your issue.
Other approach would be to uninstall MySQLdb module and reinstall it again, forcing python to compile it against a newer library.

You were right. Bluehost upgraded MySQL. Here is what I did:
1) remove the "build" directory in the "MySQL-python-1.2.3" directory
2) remove the egg
3) build the module again "python setup.py build"
4) install the module again "python setup.py install --prefix=$HOME/.local"
Morale of the story for me is to remove the old stuff when reinstalling module

Related

Import ldap in python gives gives "DLL load failed" error

I'm using the "import ldap" in a python code. This is on a windows 10 machine.
I installed the python-ldap module
pip3 install python-ldap
Installed the dependencies based on the instructions at Python Can't install packages
Also resolved all the pip deployment issues based on Installing python-ldap in a virtualenv on Windows
I'm now getting the following error when executing the import ldap statement. am I missing something here? Any ideas to resolve it?
thon39\site-packages\ldap\__init__.py", line 34, in <module>
import _ldap
ImportError: DLL load failed while importing _ldap: The specified module could not be found.
Visit the unofficial Python binaries page:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap
Download the appropriate WHL package for your system.
For example, if you're using Python 3.8 on an x64 system, download python_ldap‑3.3.1‑cp38‑cp38‑win_amd64.whl
(hint: do NOT download the +sasl version unless you have the Cyrus SASL code running on your system...)
Start the VirtualEnv for your project, if you're using one (C:\Users\youruser\.virtualenv\YourVirtualEnv\Scripts\activate.bat) -- if you're not, skip this step.
Then run pip3 install C:\Path\To\python_ldap_x.x.x-cpXX-cpXX-winXX.whl and this should install the Python DLL (pyd) file for you.

zlib module issue for local user

My requirement is to install NodeJS using sources (v8.9.4) for a local user (no root access) on Oracle Linux. When I ran the 'configure' and 'make install' it complained that the Python version was not 2.7.
Since there was no root access and I could not upgrade Python, I installed Python for the local user with the steps below.
I downloaded the sources (Python-2.7.11) and ran the configure (with --prefix option) and 'make install'.
Updated the PATH and PYTHONPATH variables to use this version of Python for this user.
Now, when I try to configure NodeJS again, it does not complain about Python 2.7 any more but now says:
File "tools/compress_json.py", line 6, in <module>
import zlib
ImportError: No module named zlib
When I checked if zlib was on the system with 'yum list installed zlib', I see
zlib.i386 1.2.3-4.el5 installed
zlib.x86_64 1.2.3-4.el5 installed
I now do not know
how the local python version can use this zlib module (or)
how/if zlib module needs to be configured into python (or)
if Python has to be installed again with some configuration for getting the zlib module.
I've searched on google and tried a few, but there was nothing conclusive that could help.

Python, Cygwin - ImportError: No module named _psycopg

I used the article on https://github.com/nwcell/psycopg2-windows and https://bitbucket.org/topper/psycopg2-win64-py27/overview to get psycopg2 installed and working on Python2.7 and Cygwin.
The install ran fine and i see the package in the /usr/lib/python2.7/site-packages/psycopg2-2.5.3-py2.7.egg/ directory.
However the import does not work.. Any idea on this error?
Python 2.7.8 (default, Jul 25 2014, 14:04:36)
[GCC 4.8.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/psycopg2-2.5.3-py2.7.egg/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: No module named _psycopg
Thanks,
Manish
I was getting this exact set of messages -- but not in my local Cygwin/Babun dev environment -- I got them when I pushed to the RHEL 7 server to test there. It took two days to flush it out, and how I solved it likely doesn't apply to you. But I learned some things that probably do.
Another cause of this error is argued at great length in these bug reports (with Python and psycopg pointing fingers at each other) -- and generally not worth the read -- read on below instead:
http://bugs.python.org/issue16047
https://psycopg.lighthouseapp.com/projects/62710/tickets/201
The gist of it? Look for some updates -- it looks like they both might have made some small changes that affect this.
Anyway... this is how I installed psycopg2 in Cygwin (assuming Babun's pact installer is available):
pact install libpq-devel
pip install psycopg2
Yup, that's it! (Some envs might also require a C compiler and python*-devel.)
An alternative to installing libpq-devel is to install Windows Postgres and add the location of its pg_config file to your PATH so that pip can compile psycopg2 -- but installing libpq-devel from the Cygwin shell is cleaner and it puts its pg_config where pip can already find it.
I installed pyscopg2 from within a virtual env but that shouldn't have mattered. What might matter, however, could be one of the following:
Python version: You were using 2.7.8 (almost the latest for the time), I was using 3.4.3. Try a later version of 2.7.
psycopg2 version: You were using 2.5.3, I was using 2.6.1.
Conflicting Python installs. Check the sys.path values from within Python to make sure it looks as you would expect. This doesn't appear to be your problem according to what you posted, but I mention it because this was ultimately my problem on RHEL 7 and how Apache was loading the virtual envs. ---- (Just another note here: I ultimately resolved the RHEL problem by compiling another mod_wsgi for Python 3.4.3, as per their instructions, to match my virtual envs. The previous mod_wsgi was running under Python 2.7.5 and that version was failing to import _psycopg from a C library. Besides, I didn't want 2.7 running at all.)
Env = python 2.7.10 (cygwin distribution), Windows 7, Cygwin 64
1) pip install psycopg2 failed as I didn't have pip
debug
2) Installed pip from here: pip.pypa.io/en/stable/installing/
3) pip install psycopg2 failed due to 'no pg_config...'
4) psycopg2 installer for win (www.stickpeople.com/projects/python/win-psycopg/) failed cause I am using cygwin's python install, not the python in the machine's registry and this installer won't allow user to install anywhere else other thatn the python that is registred with Windows
(Installer succeeded, but the files were not where I needd them.)
("Copying" the files didn't work.)
5) This (https://github.com/nwcell/psycopg2-windows) pip install "worked" (gave no errors) but when I tried to import, I got the message:
"ImportError: No module named psycopg2"
6) pip uninstall psycopg2
7) Tried to pip install libpq-dev and python-dev
"Could not find a version that satisfies the requirement libpq-dev (from versions: )
No matching distribution found for libpq-dev"
8) installed Postgres & pg_config from here http://www.enterprisedb.com/products-services-training/pgdownload#windows
9) added pg_config to path
10) pip install psycopg2 now worked
11) import psycopg2 in .py file caused core dump
Stack trace:
Frame Function Args
006001A5A60 0018007261A (000FFFFE3F4, 0000000E514, 00000000000, 000FFFFDE50)
006001A5B00 00180073DD0 (00077801FD6, 00000000000, 00000000140, 00000000000)
006001A5D50 0018012EF8F (00600010540, 00000000000, 003DB05FDB0, 6FFFFF28050)
006001A6040 0018012BC70 (0000000000D, 00000000000, 00000000000, 0018013D7DA)
00000000000 0018012C139 (006001A6030, 3630303030303030, 3036303030303030, 00000
00000B)
00000000000 0018012C30C (00000000000, 10000000A8E73, 6F007000650072, 61006C0074
0072)
00000000000 00180127BFB (00000000000, 10000000A8E73, 6F007000650072, 61006C0074
0072)
00000000000 00180071169 (01000000010, 00000000000, 00000000000, 000FFFFCE00)
000FFFFAA00 00180073D11 (B64000B00630079, 00000000088, 1D17578E1C375D4, 1D17578
E16661AE)
52004F00520052 64006F00630072 (00000000088, 1D17578E1C375D4, 1D17578E16661AE, 1
D175A09055FB4F)
52004F00520052 70002E00730065 (1D17578E1C375D4, 1D17578E16661AE, 1D175A09055FB4
F, 1D175A09055FB4F)
52004F00520052 B64000B00630079 (1D17578E16661AE, 1D175A09055FB4F, 1D175A09055FB
4F, 0000000180B)
52004F00520052 00000000088 (1D175A09055FB4F, 1D175A09055FB4F, 0000000180B, 0000
0002000)
52004F00520052 1D17578E1C375D4 (1D175A09055FB4F, 0000000180B, 00000002000, 01A0
0000020)
52004F00520052 1D17578E16661AE (0000000180B, 00000002000, 01A00000020, 45001600
000000)
52004F00520052 1D175A09055FB4F (00000002000, 01A00000020, 45001600000000, 4E004
500540058)
End of stack trace (more stack frames may be present)
(The above took ~2 days.)
12) pip install pg8000 worked
13) imported pg8000 to .py file and connected to DB
(Steps 12 and 13 took ~20 minutes.)
It's mandatory to install libpq, which sometimes is not installed as part of libpq-devel. As of now, I succedded installing libpq5.
You must use Cygwin package installer to install BOTH of the two packages:
libecpg6, for psycopg2 runtime library support, without it you will get
'ImportError: No module named _psycopg' when you run your script.
libecpg-devel, for compiling psycopg2 without it you will get a lot of
such as pthread_*** errors when you install psycopg2 using pip tool.
As time goes on, those package name may be changed, but you should know what's
you deficiency.

Installing MySQLDb python module *without* Internet Connection

Installing MySQLDb (Python module) without Internet Connection
Hi all,
I need to install MySQLDb on a SLES 11 Development Server. This Dev Server does not have access to the public internet due to corporate firewall policies. I was assuming this would merely be a nuisance which would force me to do source installations etc on things more easily installed otherwise. Instead, I have hit a wall, during my attempt to ultimately install and run Django with MySQL support.
I have downloaded and unzipped MySQL-python-1.2.4, and I am attempting to run its setup.py. However, any attempt to run setup.py, even just sudo python setup.py --help, reults in the following
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
And then of course the download fails.
I downloaded and installed the current version of the distribute module (0.7.3), via sudo python setup.py build install. I assumed this would keep mysql-python's setup.py from trying to download distribute. But that does not appear to matter. I did have a quick look at mysql-client's setup.py to see where the download was being forced. It appears that its setup.py does this:
from distribute_setup import use_setuptools
use_setuptools()
Which calls this:
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, download_delay=15, no_fake=True):
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
was_imported = 'pkg_resources' in sys.modules or \
'setuptools' in sys.modules
try:
try:
import pkg_resources
if not hasattr(pkg_resources, '_distribute'):
if not no_fake:
_fake_setuptools()
raise ImportError
except ImportError:
return _do_download(version, download_base, to_dir, download_delay)
And this, the import of pkg_resources fails (I have reproduced this from the command line); and the exception handler tries a download, which of course fails.
My understanding is that distribute is deprecated anyway, and that setuptools should be used instead. I do have setuptools installed; but is the mysqldb module hardcoded to use distribute, and possibly a specific version of distribute, and that's my issue? To be honest at this point I'm a bit confused about modules, dependencies, etc in Python (I'm quite mediocre at Python).
Thanks all,
Bean
git clone https://github.com/PyMySQL/PyMySQL or download tarball. for mysqldb: https://github.com/farcepest/MySQLdb1
untar it
run sudo python setup.py install
That's all.
Guess it's too late, but for the sake of the future googlers...
I had the same problem. To solve it I had to comment these lines:
if not hasattr(pkg_resources, '_distribute'):
if not no_fake:
_fake_setuptools()
raise ImportError
After this I was able to install MySQL-python via python setup.py install.
The answer to this question appears to be version dependent. MySQLDb version 1.2.5 (newest version as of this writing) and later do not require distribute so python setup.py install will work. Version 1.2.5 was released 01/2014 so this question is just that old.

How do I install web2py in a virtualenv in Windows 7?

I'm new to Python and I'm trying to install web2py in a virtualenv. I'm running a 32 bit python 2.7.3 installation on a 64 bit Windows 7.
From what I read, this should be the process:
install virtualenv (done)
create the virtualenv (done)
install pywin32 in that env (I've read it needs to be installed before the web2py installation)
install web2py in that env
First and foremost: is that right? If so, then...
I tried installing pywin32 through
'''easy_install pywin32-218.win32-py2.7.exe'''
It went fine. Then, I checked the virtual environment's site-packages for a pywin32 folder and it was there, but I couldn't import it into python ('''ther's no module pywin32'''). The environment was definitely active (I double-checked).
As a test, without using virtualenv, I double-click-installed the pywin32 binary (downloaded the 32 bit version for python 2.7 -- pywin32-218.win32-py2.7.exe) but got an error at the end:
'''close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr'''
I downloaded the file again (could be corrupted), tried installing it again but got the same result.
Could anybody guide me or point me to a step-by-step install of pywin32 (if necessary) and then web2py for windows 7? I'd really appreciate it.
its a bug: http://sourceforge.net/tracker/?func=detail&aid=3402824&group_id=78018&atid=551954,
workaround here : http://pywin32.hg.sourceforge.net/hgweb/pywin32/pywin32/rev/a64d8ac23e61
similar to this: Error installing and running pywin32 2.7
In my experience, the command easy_install pywin32-218.win32-py2.7.exe under an active virtualenv works fine.
To test the installation of pywin32, from python you can try:
from win32api import GetVersionEx
print GetVersionEx()
Obtaining something similar to (windows major version, minor version, build number, platform id, additional informations):
(6, 1, 7601, 2, 'Service Pack 1')
You cannot import module pywin32 because it doesn't exist.
After the installation of pywin32, you can install web2py under the active virtualenv (I tested it until to opening the admin interface, no guarantee after this :-):
download the source code from http://www.web2py.com/init/default/download
unzip it to ...\virtualenvdir\Lib\site-packages\ (obtaining: ...\virtualenvdir\Lib\site-packages\web2py\...)
cd to ...\virtualenvdir\Lib\site-packages\web2py
start the web2py server: python web2py.py
At the date, I couldn't install web2py using pip. First of all, it grabs an old version of web2py from PyPy. When I tryed to use this version of web2py I got an error ImportError: No module named .... The same using pip on a copy of the web2py source file.

Categories