I am getting the following error (on osx):
Traceback (most recent call last):
File "./permission_analysis.py", line 9, in <module>
import psycopg2
File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found
So this looks a lot like this question:
Psycopg2 image not found
Except that the most popular upvoted answer doesn't work:
$ sudo ln -s /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/lib
$ sudo ln -s /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/lib
If I try to do either of those commands, it says the file already exists.
I feel your pain with trying to get Psycopg2 to work on Mac. I tried for ages, but i got it working in the end.
I asked this question and answered it here
Thanks guys.
#maxymoo I went with your suggestion. I have installed anaconda2. The install updated my path to include /anaconda/bin.
Then using the navigator I installed pyscopg2. Now I am able to use this in the shebang and my scripts execute fine and i'm able to import this module.
Gurmokhs-MBP:rest Gurmokh$ python
Python 2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
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://anaconda.org
>>> import psycopg2
if psycopg2.connect("dbname='postgres' user='postgres' host='localhost'"):
... print "connection made"
...
connection made
>>>
Related
I use a Gentoo-based Docker image for CI with multiple versions of Python. Recently, I've started experiencing errors because one tool (coveralls) requires sqlite, which is missing. sqlite is part of the Python standard library.
This can be checked from the command line
>>> removing all .pyc files
>>> executing command
me#5b35f99c08af /source $ python
Python 3.6.9 (default, Dec 27 2019, 12:15:49)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sqlite3'
I couldn't find any notes in the Gentoo packaging database about this, but I'm not really familiar with it as an OS. I assume there must have been a problem building some relevant library.
Python has been installed like this:
RUN emerge -q -u dev-lang/python:3.6
But the error occurs for all the versions I'm currently testing with: >= 3.5. Any ideas as to what I'm doing wrong?
I am running pypy and after adding the path to the bitarray library to sys.path I still can't import the module:
Python 2.7.3 (87aa9de10f9ca71da9ab4a3d53e0ba176b67d086, Feb 10 2014, 05:26:49)
[PyPy 2.2.1 with GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``every VM should come with neural
network trained to recognize microbenchmarks and randomly fluctuate them
+/-9000%''
>>>> import sys
>>>> sys.path.append('/usr/local/lib/python2.7/dist-packages/')
>>>> sys.path.append('/usr/local/lib/python2.7/dist-packages/bitarray/')
>>>> import bitarray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/bitarray/__init__.py", line 11, in <module>
from bitarray._bitarray import _bitarray, bitdiff, bits2bytes, _sysinfo
ImportError: No module named bitarray._bitarray
In regular python (CPython installed from aptitude) importing bitarray works fine and I haven't made any modifications to the module after installing it with pip. What's wrong here?
Just in case you need it here is the content of the bitarray dir:
$ls /usr/local/lib/python2.7/dist-packages/bitarray/
_bitarray.so __init__.py __init__.pyc test_bitarray.py test_bitarray.pyc
UPDATE
After creating a virtualenv for pypy and installing bitarray with pip as Sunny suggested I still get an ImportError:
$ ls my-pypy-env/site-packages/bitarray
_bitarray.pypy-22.so __init__.py __init__.pyc test_bitarray.py test_bitarray.pyc
$ cd my-pypy-env/
~/my-pypy-env$ ./bin/activate
~/my-pypy-env$ pypy
Python 2.7.3 (87aa9de10f9ca71da9ab4a3d53e0ba176b67d086, Feb 10 2014, 05:26:49)
[PyPy 2.2.1 with GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``__xxx__ and __rxxx__ vs operation
slots: particle quantum superposition kind of fun''
>>>> import sys
>>>> sys.path.append('/home/sofia/my-pypy-env/site-packages/bitarray')
>>>> import bitarray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bitarray
UPDATE 2
Sunny's solution is correct. The new problem was appending /site-packages/bitarray
instead of just /site-packages/. I would have though that virtualenv would add this to the path automatically but it seems that it doesn't.
The _bitarray module looks like a CPython extension, which is written directly in C.
CPython extension modules does not work directly in PyPy without any changes. You either need to install PyPy compatible version of the module, or do the required changes manually.
To install pypy compatible version, use the following commands:
# If pypy is installed globally
/path/to/pypy/pypy-2.1/bin/pip install bitarray
# If using virtualenv
source /path/to/virtualenv/env/bin/activate
pip install bitarray
Here are a couple of links from PyPy FAQs about this issue:
http://doc.pypy.org/en/latest/faq.html#module-xyz-does-not-work-with-pypy-importerror
http://doc.pypy.org/en/latest/faq.html#do-cpython-extension-modules-work-with-pypy
I've recently given up on macports and gone to homebrew. I'm trying to be able to import numpy and scipy. I seem to have installed everything correctly, but when I type python in terminal, it seems to run the default mac python.
I'm on OSX 10.8.4
I followed this post: python homebrew by default
and tried to move the homebrew directory to the front of my %PATH by entering
export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
then "echo $PATH" returns
/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
however when I look for where my python is by "which python", I get
/usr/bin/python
For some reason when I import numpy in interpreter it works but not so for scipy.
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named scipy
>>>
What do I need to do to get python to run as my homebrew-installed python? Should this fix my problem and allow me to import scipy?
Homebrew puts things in a /usr/local/Cellar/<appname> directory, if I'm not mistaken. You should find the bin of the python in there and put it in your path before hitting /usr/bin.
For example, on my 10.8, python is located at /usr/local/Cellar/python/2.7.5/bin and I put that directory before /usr/bin/python in my PATH variable.
I do that similarly for other instances of me wanting to use homebrew version of an app, another example being sqlite.
I want to have Z3python on my Ubuntu 12.04 64-bit. I downloaded Z3 source, and compiled like below:
$autoconf
$./configure
$sudo make
$sudo make a
$sudo make o
Everything went well, but then I tried:
$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import z3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named z3
It seems Z3python is not installed yet? I followed exactly the instructions in README, but it seems to miss something regarding Python binding?
please ignore, what i got is the old version of Z3.
a recommendation: please provide the source code of the latest Z3 in the homepage. i couldnt find it anywhere, then wrongly got the old version. finally, i had to download the latest version from the SourceControl, which was a bit tricky.
i'm tying to play with sqlite3 on my centos server but it reports always the same error (module installed)....
Python 2.7.3 (default, Jun 29 2012, 19:03:18)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
on ubuntu and so on works fine.... any ideas of what i'm missing here?
i recompile the 2.7.3 again and it catch the sqlite3 libs well.
If you are under RHEL/centos 6, you can try this:
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/sqlite3/
This will work for CentOS:
ln -s /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/
/usr/local/lib/python2.7/ is already on python's path. No need to duplicate the file or add the python's path.
first find:
find / -name _sqlite3.so
/usr/usr/lib/python2.6/lib-dynload/_sqlite3.so
/usr/local/service/python2.7/lib/python2.7/lib-dynload/_sqlite3.so
/usr/lib64/python2.6/lib-dynload/_sqlite3.so
next
cp /usr/local/service/python2.7/lib/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/sqlite3/
this centso 6.5 python2.7.10
If you're using Python 2.7.3 on a Red Hat 5 or CentOS 5 machine, there was a bug that prevented the SQLite modules from compiling properly when building Python from source; you should see an error message when running make. It's since been fixed in 2.7.4 so your best option is to upgrade.
If that's not possible, then there's a patch available. Here's the bug page and the patch.