0

I have the pgdb module installed on my MacOsX development box, my code works (specifically a line that is pgdb.connect(etc..) works great. I runt his code on my main server (linux) and it it says module has no attribute connect.

I think it is a version issue so I do what is suggested here to view the versions:

How to check version of python modules?

That is I do:

python
import pgdb
print pgdb.__version__

On my macosX box, returns the version just fine on my development machine it gives the error again:

AttributeError: 'module' object has no attribute '_version_'

Strange thing is, doing an import pgdb does not throw an error but it acts like it is not installed on my production box. Perhaps it is a library mangling on the box I am not aware of? I should say import pgdb as myspecialsomething (That didn't do it still says no connect) ?

The other thing is, I did do a sanity check and did a sudo pip install pgdb on the production box and got this:

Requirement already satisfied: pgdb in /usr/lib/python2.7/site-packages

Requirement already satisfied: psycopg2>=2.5.2 in /usr/lib64/python2.7/site-packages (from pgdb)

Also, now this isn't an issue of the name clashing like one poster thought might be a duplicate of. Something else is going on, though interestingly enough when I check the file my os x is using and the file my centos is using for pgdb I get two different answers: (paths wouldn't surprise me but files themselves does)

MacOS X:

 >>> pgdb.__file__
 '/usr/local/lib/python2.7/site-packages/pgdb.pyc'

CentOS:

 >>> pgdb.__file__
 '/usr/lib/python2.7/site-packages/pgdb/__init__.pyc'

No idea for the difference.

Community
  • 1
  • 1
Codejoy
  • 3,722
  • 13
  • 59
  • 99
  • I would go to the package and see if the folders are populated, your setup sounds very broken. – Natecat Jan 17 '17 at 23:07
  • Guessing on the deployed side not the mac side, I would agree...I am not the sole manager of this box. Here is the results of the ls on this location:/usr/lib/python2.7/site-packages/pgdb has the files __init__.py __init__.pyc pgdb.py pgdb.pyc – Codejoy Jan 17 '17 at 23:10
  • Possible duplicate of [Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"](http://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – Łukasz Rogalski Jan 17 '17 at 23:30
  • I looked at this, unless I am misunderstanding what the link is saying my code I am running is some_test.py which certainly is not pgdb.py. Though I do suspect multiple versions/installed somehow. I tried this with various modules all are broke. Even an import math with print math.__version__ gives same errors :/ – Codejoy Jan 17 '17 at 23:34

1 Answers1

0

You likely have file pgdb.py in your current working directory, i.e. the directory you start Python from. Remove or rename it and try again.

You can find out where module is located with:

print pgdb.__file__

or:

import os

print os.path.abspath(pgdb.__file__)
Mike Müller
  • 82,630
  • 20
  • 166
  • 161
  • What do you mean by current directory, as stated above there is a folder under some others named site-packages and pgdb is a folder in there with init.py, init.pyc and pgdb.py and pgdy.pyc? – Codejoy Jan 17 '17 at 23:12
  • I mean the directory you start your script from. – Mike Müller Jan 17 '17 at 23:14
  • Folder I start script from does not have a pgdb.py. I wonder if there are somehow multiple installs of this or if I can just do a pip uninstall/remove somehow and try again from scratch on installing the pgdb ? – Codejoy Jan 17 '17 at 23:17
  • Okay I did that os print and got this: /usr/lib/python2.7/site-packages/pgdb/__init__.pyc Not sure if this is relevant but I was testing with gdal (which I know exsists on the server as well) if I do a import gdal and then a print gdal.__version__ I get that module error. If I do a from osgeo import gdal and then do that, then the print gdal.__version__ works fine. I think I have to do a from on the pgdb too? maybe? – Codejoy Jan 18 '17 at 15:56
  • also just did this: >>> from pgdb import connect and it fails – Codejoy Jan 18 '17 at 15:59
  • Also looking at my mac the file points to there: /usr/local/lib/python2.7/site-packages/pgdb.pyc it is like it is pointing to the wrong file? Or perhaps the OS difference requires mac os to use pgdb.pyc not __init__.pyc? – Codejoy Jan 18 '17 at 16:43
  • I broke out my windows machine with python 2.7x on it. I did a pip install pgdb on it and then checked the file path, same as the centos points to the __init__.pyc and has the same issue doing a print pgdb.__version__ :( So tells me I am doing something wrong and might be a simple fix but no idea what that could be. – Codejoy Jan 18 '17 at 21:47