OpenBSD, PostgreSQL9.2, python2.7
Trying to import psycopg2 module from python command line:
Python 2.7.3 (default, Aug 3 2012, 05:33:56)
[GCC 4.2.1 20070719 ] on openbsd5
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 67, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: Cannot load specified object
psycopg2 is compiled and installed. I saw _psycopg.so in /site-packages/psycopg2 folder. Maybe he can not see this library ?
The psycopg2 python module includes an extension written in C. That extension cannot be loaded, because another C library that it is depending on is missing.
Check that you still have the PostgreSQL client libraries installed, and that psycopg2 can find it.
Note that if you run Django in a WSGI server, you need to have set the LD_LIBRARY_PATH environment variable before the WSGI server starts. Alternatively, recompile the psycopg2 extension with LD_RUN_PATH=/usr/local/pgsql/lib to 'hardcode' the path to the PostgreSQL client library at linking time, removing the need to set LD_LIBRARY_PATH.
A last resort would be to add the /usr/local/pgsql/lib path to /etc/ld.so.conf, see the ld.so(8) manpage.
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?
Pythonproject directory structure is like
--test
--upperlevel
-- __init__.py
-- manager.py
-- UpperLevel.py
this files in turn contains
# __init__.py
msg = "YAYY printing !!!"
print msg
# UpperLevel.py
from upperlevel import msg
# manager.py
import UpperLevel
So in my local MAC book with python 2.7.10, started a python shell in test directory.
From that shell,
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import upperlevel.manager
YAYY printing !!!
>>>
it worked !!!!
However i started a virtual machine (ubuntu 14.04 and python 2.7.10) with vagrant and added same test directory to it.
so if i did the same thing
Python 2.7.10 (default, Jul 13 2017, 19:26:24)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import upperlevel.manager
YAYY printing !!!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "upperlevel/manager.py", line 1, in <module>
import UpperLevel
File "upperlevel/UpperLevel.py", line 1, in <module>
from upperlevel import msg
File "upperlevel/upperlevel.py", line 1, in <module>
from upperlevel import msg
ImportError: cannot import name msg
>>>
So my questions are
1) why it is not working in the later case, i tried the same in docker and getting the same error
2) there is no such file in my project, File "upperlevel/upperlevel.py", line 1, in
3) why it is searching for upperlevel.py instead of UpperLevel.py
FYI
It looks like if we do "import upperlevel" from UpperLevel.py it is refering back to itself instead of going to upperlevel/init.py.
UPDATE:
I understood where the problem is from.... my test directory(volume) is being shared between mac and vagrant/docker, somehow UpperLevel.pyc is being treated as upperlevel.pyc in that shared volume.
Instead of running in a shared directory i created same folders/files in /home/vagrant and it worked.
It seems you are running from a Mac environment, and it is possible that the Python default search paths are different for those builds, despite the version being similar.
Try comparing:
import sys
print(sys.path)
It is probable that the default installation search paths might differ.
You can use the environment variable $PYTHONPATH to add additional import paths, while I don't really like this method it can be sufficient in most cases.
You can also setup your package in a proper module installation path.
Finally answering my own question...the problem is mac has a case insensitive file system and when it is mounted on linux, python is trying to use ubuntu mode of module reading like in the case sensitive way on a case insensitive File system.
After a lot of research found this link for docker https://github.com/docker/for-mac/issues/320 so those when using ubuntu docker with python on a mac be careful with your naming conventions.
I am trying to resolve some dependencies for the MYSQL connector for Python on Angstrom.
From the command line I get the following error:
Python 2.6.6 (r266:84292, Feb 25 2011, 16:50:01)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named io
I thought that IO was a base-level module. It appears to be up-to-date:
# opkg install python-core
Package python-core (2.6.6-ml12.2.6) installed in root is up to date.
Shouldn't IO be available by default, and what can I do to resolve this issue?
Thanks to Padraic Cunningham who lead me on the path to a solution.
I found that several files, including io.py were missing from the install. Building the Angstrom for the Beagleboard (XM) image from the Angstrom website did not include these files (or subsequent modifications I made deleted them?). I rebuilt Python, keeping the identical version, from the Python source.
I had to then rebuild the MySQL connector (from MySql/Oracle). (All my other modules including OpenCV continued to work without issue)
This worked and I am now able to query the database.
One additional note. Once all the dependencies were resolved, I still could not connect to the database. The problem was that the MySQL connector was assuming a TCP/IP connection rather than file based socket. So I had to add the following to the connection string:
unix_socket="/tmp/mysql.sock"
Such that the full connection string looked like this:
cnx = mysql.connector.connect(user='username', password='password', host='localhost', database='dbname', raise_on_warnings=True, unix_socket="/tmp/mysql.sock")
I'm having some trouble using OpenCV2.2 with Python2.7.1 (which should be compatible). I've installed OpenCV to D:\OpenCV2.2PreCom\, added the D:\OpenCV2.2PreCom\Python2.7\Lib\site-packages path to sys.path as well as to the environment variable PYTHONPATH.
I've also made sure the D:\OpenCV2.2PreCom\bin path is added to the Path environment variable. However, when I try to access the cv.pyd file (which is in D:\OpenCV2.2PreCom\Python2.7\Lib\site-packages\) by typing 'import cv',
I get an importerror:
The IDLE looks like this:
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import sys
>>> sys.path.append('D:\OpenCV2.2PreCom\Python2.7\Lib\site-packages')
>>> import cv
Traceback (most recent call last):
File "<pyshell#64>", line 1, in <module>
import cv
ImportError: DLL load failed: The specified module could not be found.
>>>
So what else can I try to make Python import OpenCV?
With kind regards.
Not a Windows user, but seems that the Python module cannot find the DLL. It is not a problem of PYTHONPATH.
Did you install it or just unpack it? Try installing it with the installer, it should take care of positioning the DLL in the right path.
Can you try escaping the backslashes? Try this:
>>>> sys.path.append('D:\\OpenCV2.2PreCom\\Python2.7\\Lib\\site-packages')
You should copy the content of D:\OpenCV2.2PreCom\Python2.7\Lib\site-packages (there should be two files inside ) in the site-packages of your python install, the default one being C:\Python2.7\Lib\site-packages and escape you back lashes or replace them with /
I am trying to use an application that has a dependency of ctypes, but am getting this error:
$ python peach.py -t ~/Desktop/fuzz/wav/template.xml
] Peach 2.3.6 Runtime
] Copyright (c) Michael Eddington
Traceback (most recent call last):
File "peach.py", line 335, in <module>
from Peach.Engine import *
File "/opt/Peach-2.3.6/Peach/__init__.py", line 40, in <module>
import Publishers, Transformers
File "/opt/Peach-2.3.6/Peach/Publishers/__init__.py", line 37, in <module>
import file, sql, stdout, tcp, udp, com, process, http, icmp, raw, remote, dll, smtp
File "/opt/Peach-2.3.6/Peach/Publishers/file.py", line 37, in <module>
from Peach.Engine.engine import Engine
File "/opt/Peach-2.3.6/Peach/Engine/engine.py", line 835, in <module>
from Peach.Engine.state import StateEngine
File "/opt/Peach-2.3.6/Peach/Engine/state.py", line 38, in <module>
import sys, re, types, time, struct, ctypes
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
I have installed py-ctypes from ports, but it seems to only be a Python 2.4 version:
$ port contents py-ctypes
Port py-ctypes contains:
/opt/local/lib/python2.4/site-packages/_ctypes.so
/opt/local/lib/python2.4/site-packages/_ctypes_test.so
/opt/local/lib/python2.4/site-packages/ctypes/__init__.py
/opt/local/lib/python2.4/site-packages/ctypes/__init__.pyc
/opt/local/lib/python2.4/site-packages/ctypes/_endian.py
/opt/local/lib/python2.4/site-packages/ctypes/_endian.pyc
/opt/local/lib/python2.4/site-packages/ctypes/macholib/__init__.py
/opt/local/lib/python2.4/site-packages/ctypes/macholib/__init__.pyc
/opt/local/lib/python2.4/site-packages/ctypes/macholib/dyld.py
/opt/local/lib/python2.4/site-packages/ctypes/macholib/dyld.pyc
/opt/local/lib/python2.4/site-packages/ctypes/macholib/dylib.py
/opt/local/lib/python2.4/site-packages/ctypes/macholib/dylib.pyc
I then tried to run the application via python2.4, but it seems the application uses syntax that is only available in 2.5:
$ python2.4 peach.py -t ~/Desktop/fuzz/wav/template.xml
File "peach.py", line 498
finally:
^
SyntaxError: invalid syntax
My python install is also from OSX ports, and I noticed in the Peach application, it defines python as:
#!/usr/bin/python
Will that mess with anything if my default python executable points to my port installation (and I am running 'python peach.py')?
$ which python
/opt/local/bin/python
Is there any work around for this?
ctypes for python2.5?
Ability to add 2.4 libraries to 2.5 path?
A simple solution would be to use the native Python build that is included with Mac OS. This definitely works with the latest release of Mac OS X 10.6.4, which has Python 2.6.
Here is an example showing that '_ctypes' is being imported successfully:
mariah:~ joet3ch$ /usr/bin/python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from _ctypes import Union, Structure, Array
>>>
If you have issues after this, try looking at the sys.path attribute to see which modules and versions are in your path.
Here is an example of viewing the contents of sys.path on a fresh Mac OS 10.6.4 build:
mariah:~ joet3ch$ /usr/bin/python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Python/2.6/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode']
>>>
ctypes is a standard Python library since version 2.5, so py-ctypes is not needed. The line at which you get an ImportError still exists in my 2.6.5 installation.
I do not own OSX, so my question is: does /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5 belong to the standard installation of Python 2.5, or may this belong to a possibly broken installation of some framework?
In a running python shell, you could inspect the value of sys.path. Maybe there is some broken library that precedes the standard library.
The shebang line #!/usr/bin/python is interpreted by the OS if it is the first line of an executable script that is invoked directly like an ordinary program. In all other cases, this is just a comment. In particular, the line is ignored if you invoke the script as in python myscript.py or if it is imported by other Python code.