开发者

Import psycopg2 from python script

I am trying to use psycopg2 installed by easy_install in a python script.

This is the header of my script :

#!/usr/bi开发者_运维百科n/python2

import sys,xml.sax
import psycopg2

When I execute it, an error happens :

Traceback (most recent call last):
   File "./myscript.py", line 4, in <module>
      import psycopg2
ImportError: No module named psycopg2

But if I try in a basic python shell, it works well :

$ python2
Python 2.7 (r27:82500, Oct  6 2010, 12:29:13)
[GCC 4.5.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>>

Do you have an explanation to this problem ?

Thanks


Each sequence is being performed with a different installation of Python. Use which python2 to verify.


You are using two different Python interpreters. Triple check that.


install python_select.this lets switch between different python versions.

sudo port install python_select 

on the shell do

 python_select -l 
try switching to the default python version.

for linux, use virtualenv

 sudo pip install virtualenv      #install virual env

      mkdir ~/.virtualenvs      #make virtual envs directory

      export WORKON_HOME=$HOME/.virtualenvs    #add environment variables
      source /usr/local/bin/virtualenvwrapper.sh
      source ~/.bashrc

     mkvirtualenv  foo  #make your virtual environment named foo

re install pysycopg2

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜