1

I'm running Ubuntu. I installed python2.7 and the latest version of Postgresql.

When I installed psycopg, the package showed up in the default Ubuntu version of python instead of the 2.7 version that I want to use.

I tried to reinstall from within the directory I wanted, but it still referenced the other python. When I open the python shell, the version in 2.7.

How can I install psycopg into 2.7?

Thanks for your help.

Joe

Stack after installation:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site.py", line 562, in <module>
    main()
  File "/usr/lib/python2.7/site.py", line 544, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/lib/python2.7/site.py", line 271, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/lib/python2.7/site.py", line 246, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/lib/python2.7/site.py", line 236, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/lib/python2.7/sysconfig.py", line 543, in get_config_var
    return get_config_vars().get(name)
  File "/usr/lib/python2.7/sysconfig.py", line 442, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/lib/python2.7/sysconfig.py", line 303, in _init_posix
    makefile = _get_makefile_filename()
  File "/usr/lib/python2.7/sysconfig.py", line 297, in _get_makefile_filename
    return os.path.join(get_path('platstdlib').replace("/usr/local","/usr",1), "config" + (sys.pydebug and "_d" or ""), "Makefile")
AttributeError: 'module' object has no attribute 'pydebug'
jabs
  • 1,694
  • 4
  • 19
  • 36

2 Answers2

1

apt works with the Python it installed in the first place.

You need to use easy_install (or, better, pip) to install additional libraries to the Python you installed yourself.

Community
  • 1
  • 1
Helgi
  • 5,428
  • 1
  • 31
  • 48
  • Thanks - it looks like it installed correctly (meaning I find pyscopg2 in my python install (/usr/lib/python2.7/dist-packages) but when I try to compile my django implementation, it claims that there is an 'error loading psycopg module: no module named psycopg'. Is there a way to test to confirm the install is correct (so I can focus on the django issue)? – jabs Dec 07 '11 at 21:24
  • @jabs How about running `import psycopg2` in your `python2.7` interpreter? If it doesn't fail, the module must be there. However, it's suspicious that the error message claims _psycopg_, not psycopg2 is not found. Are you sure the Django itself is also installed to the correct Python instance? Hint: When you talk about an error, giving the stack trace never hurts. – Helgi Dec 07 '11 at 22:28
  • I think I found my problem. I have 2 installs of python2.7. One at /usr/lib/ and the other at /usr/local/lib/ – jabs Dec 08 '11 at 16:42
  • 1
    sorry - not all of that came through... Anyway - Since I narrowed down the problem I thought I'd clean it up a little and, like a genius, I simply removed the /usr/local/lib installation. I continued to get errors, so I reinstalled python into /usr/lib using: wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz tar xzf Python-2.7.2.tgz cd Python-2.7.2 ./configure --prefix=/usr/lib/python-2.7.2 make make install This didn't seem to help. Now, when I type in python, I don't get the shell anymore. Rather than screwing it up more, I'll ask again (this time, with a trace below) – jabs Dec 09 '11 at 00:37
  • thanks @Helgi Traceback (most recent call last): File "/usr/lib/python2.7/site.py", line 562, in main() File "/usr/lib/python2.7/site.py", line 544, in main known_paths = addusersitepackages(known_paths) File "/usr/lib/python2.7/site.py", line 271, in addusersitepackages user_site = getusersitepackages() File "/usr/lib/python2.7/site.py", line 246, in getusersitepackages user_base = getuserbase() # this will also set USER_BASE File "/usr/lib/python2.7/site.py", line 236, in getuserbase USER_BASE = get_config_var('userbase') – jabs Dec 09 '11 at 00:40
  • @jabs: Sorry if I'm harsh, but the comments are _not_ for stack traces. It's unreadable. Can you please add their content to your original post, where you can apply formatting? My eyes hurt. – Helgi Dec 09 '11 at 00:53
  • @Helgi- If you had called me the names you thought of, that would have been harsh. Asking for a formatted trace (telling me that I can edit the original post) was quite helpful and not harsh at all. (I should have seen the 'edit' button, but missed it). – jabs Dec 09 '11 at 01:42
  • thanks for helping me understand that ubuntu installs its own version of python and that my apps were being installed into a version I didn't know about. – jabs Dec 09 '11 at 16:04
1

Jabs, you're going to have to familiarize yourself with installing and configuring projects yourself. Afterwards, the difference between doing it by hand and using apt-get should be obvious. It often useful to utilize both a package manager, and installing from source when you want to be on the cutting edge on some things but not others (and it saves a lot of time). I recommend trying to stick to the package manager for most things. I noticed a comment where you overwrote the OS installed Python. This is generally NOT a good idea.

./configure --prefix=

To learn more use:

./configure -h

Others environment variables (from configure -h)

  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

You also may want to look in setup.py when configuring and installing Python.

Also of use for figuring out what's going on and fixing it:

Derek Litz
  • 10,529
  • 7
  • 43
  • 53
  • Hi @Derek. Thanks for all of this info. Just a small clarification...I need more experience on Ubuntu (not necessarily installing Django), since I just installed it yesterday on a vm. That said, this is certainly going to help. I'll just throw this ubuntu away and create another vm, and **not** delete the OS install. I expect that'd be quicker, and potentially less painful down the road, than finding all of the files and paths that need modified. – jabs Dec 09 '11 at 03:53