[Tutor] can't import module
Dave S
pythontut at pusspaws.net
Sun Jul 2 18:51:19 CEST 2006
Here goes ...
I have two files test1 and test2 ...
dave at dave-comp:~$ ls -l
total 37620
drwx------ 8 dave dave 4096 2006-06-30 23:26 Desktop
drwxr-xr-x 9 dave dave 4096 2006-06-15 22:48 google-earth
drwxr-xr-x 13 dave dave 4096 2006-05-27 09:51 my_files
drwxr-xr-x 2 dave dave 4096 2006-06-24 21:29 Pictures
drwxr-xr-x 4 dave dave 4096 2006-07-02 03:00 PodCasts
drwxr-xr-x 2 dave dave 4096 2006-06-16 21:30 qemu
drwxr-xr-x 9 dave dave 4096 2006-06-30 22:30 SecondLife_1_10_5_1
-rw-r--r-- 1 dave dave 38438806 2006-06-30 18:53 SecondLife_1_10_5_1.tar.bz2
drwxr-xr-x 2 dave dave 4096 2006-07-02 17:43 test1
drwxr-xr-x 2 dave dave 4096 2006-07-02 17:41 test2
Two simple scripts .... parent and child ...
dave at dave-comp:~$ cd test2
dave at dave-comp:~/test2$ cat child.py
#!/usr/bin/env python
# -*- coding: iso8859_1 -*-
def hello():
print 'child says hello'
dave at dave-comp:~/test2$ cd ../test1
dave at dave-comp:~/test1$ cat parent.py
#!/usr/bin/env python
# -*- coding: iso8859_1 -*-
from child import hello
def test():
print 'parent says hello'
hello()
test()
And I hit my problem :(
dave at dave-comp:~/test1$ ./parent.py
Traceback (most recent call last):
File "./parent.py", line 4, in ?
from child import hello
ImportError: No module named child
PYTHONPATH ...
dave at dave-comp:~/test1$
dave at dave-comp:~/test1$
dave at dave-comp:~/test1$ echo $PYTHONPATH
/home/dave/my_files/my_gg/gg1.4/configs:/home/dave/my_files/my_gg/gg1.4/logs:/home/dave/my_files/my_gg/gg1.4/get_data:/home/dave/my_files/my_gg/gg1.4/gg_utils:/home/dave/my_files/my_gg/gg1.4/ipc:/home/dave/my_files/my_gg/gg1.4/process_data:/home/dave/my_files/my_gg/gg1.4/common_utils:/home/dave/test2
dave at dave-comp:~/test1$
And where PYTHONPATH is set ...
dave at dave-comp:~/test1$ cat ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
#export HISTCONTROL=ignoredups
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color)
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:
\[\033[01;34m\]\w\[\033[00m\]\$ '
;;
*)
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
;;
esac
# Comment in the above and uncomment this below for a color prompt
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:
\[\033[01;34m\]\w\[\033[00m\]\$ '
# If this is an xterm set the title to user at host:dir
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
;;
*)
;;
esac
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
#if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
#fi
# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
#alias dir='ls --color=auto --format=vertical'
#alias vdir='ls --color=auto --format=long'
fi
# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi
PYTHONPATH=/home/dave/my_files/my_gg/gg1.4/configs:/home/dave/my_files/my_gg/gg1.4/logs:/home/dave/my_files/my_gg/gg1.4/get_data:/home/dave/my_files/my_gg/gg1.4/gg_utils:/home/dave/my_files/my_gg/gg1.4/ipc:/home/dave/my_files/my_gg/gg1.4/process_data:/home/dave/my_files/my_gg/gg1.4/common_utils:/home/dave/test2
export EDITOR=vi
dave at dave-comp:~/test1$
Dave
More information about the Tutor
mailing list