Results 1 to 8 of 8

Thread: Problem with petsc4py when reading importing it from a python file...

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Beans
    15

    Problem with petsc4py when reading importing it from a python file...

    I run a python program and I get :


    s117555@ubuntu:~/SUmb_2/sumb/python/examples$ python nk_test.py
    Traceback (most recent call last):
    File "nk_test.py", line 17, in <module>
    import petsc4py
    ImportError: No module named petsc4py
    s117555@ubuntu:~/SUmb_2/sumb/python/examples$

    BUt I know I have petsc4py already since when I write sudo easy_install petsc4py I get the following:

    s117555@ubuntu:~/SUmb_2/sumb/python/examples$ sudo easy_install petsc4py
    [sudo] password for s117555:
    Searching for petsc4py
    Best match: petsc4py 3.3
    petsc4py 3.3 is already the active version in easy-install.pth

    Using /usr/local/lib/python2.7/dist-packages
    Processing dependencies for petsc4py
    Finished processing dependencies for petsc4py
    s117555@ubuntu:~/SUmb_2/sumb/python/examples$

    SO I realy dont know what is going on..? WHy is is not in my python library?? is it like that or I am getting confused..

  2. #2
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Problem with petsc4py when reading importing it from a python file...

    It looks like easy_install may have installed the modules to a location that's not part of your $PYTHONPATH somehow. Is this your first time using easy_install, and can you confirm that you configured it correctly? Here's some docs on configuring just in case:

    http://packages.python.org/distribut...tion-locations

  3. #3
    Join Date
    Nov 2012
    Beans
    15

    Re: Problem with petsc4py when reading importing it from a python file...

    Hey, I dont know that, I will read it, but its funny when I type cd ${PYTHONPATH} THE TERMINAL gets me to home reight away... that shouldnt be right???

  4. #4
    Join Date
    Nov 2012
    Beans
    15

    Re: Problem with petsc4py when reading importing it from a python file...

    Actualy when I got python I did not specified which folder or user or anything, so he may just have installe dit in a default place right???

    WHat happends is in my .bschr file I have an
    export PYTHONPATH=${PYTHONPATH}:${HOME}/SUmb_2/mdo_import_helper

    Becasue I need to export it for an aplication, according to my teacher... could have this damaged the path petsc4py was installed

  5. #5
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Problem with petsc4py when reading importing it from a python file...

    The line you've added to .bashrc just appends the directory '${HOME}/SUmb_2/mdo_import_helpe' to the current Python path. So that shouldn't break anything as far as I can tell.

    $PYTHONPATH is not a bash environmental variable. So, if you try to 'cd $PYTHONPATH' it's the same as just typing 'cd' (which is a shortcut to go to your $HOME directory) as $PYTHONPATH is null. You can test this by typing:

    Code:
    echo $PYTHONPATH
    which won't return anything.

    I have not used easy_install before myself, I don't know the specifics of the configuration file and where it installed modules by default. Perhaps someone with a little more experience would know. But, as it stands now, your $PYTHONPATH looks to be the standard $PYTHONPATH plus ${HOME}/SUmb_2/mdo_import_helper. If you want to check, launch python from the terminal and run these two commands:

    Code:
    import sys
    print sys.path
    Note, the syntax is a little different if you're running Python 3.

    What you need to do is make sure the configuration of easy_installer is correct (to save future headaches!), find out where the petsc4py module was installed, and make sure that the location of that module is part of your $PYTHONPATH.

    Hope that makes sense

  6. #6
    Join Date
    Nov 2012
    Beans
    15

    Re: Problem with petsc4py when reading importing it from a python file...

    Thanks man I will try that, in the mean while, when I run echo $PYTHONPATH, I do get something...

    s117555@ubuntu:~$ echo $PYTHONPATH
    :/home/s117555/SUmb_2/mdo_import_helper

    For some reason I wrote before in the PYTHONPATH = to the actual directory of my python,.. but then erase it but kept the line of export....

    Now I run the python, and ..
    s117555@ubuntu:~$ python
    Python 2.7.3 (default, Nov 9 2012, 14:40:22)
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> print sys.path
    ['', '/home/s117555', '/home/s117555/SUmb_2/mdo_import_helper', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/home/s117555/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages']
    >>>

    The location where my petsc4py is not there cuz I cheked and it is :

    /usr/local/lib/python2.7/dist-packages

    But since my location in the SUmb_2 directory actualy appear I am going to try if by adding the previous directory as
    export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python2.7/dist-packages

    adds the directory and lets see if it i solved.... thansk for helping me understand man.. =) I will keep checking

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •