[New-bugs-announce] [issue8955] import doesn't notice changes to working directory

James report at bugs.python.org
Wed Jun 9 17:44:15 CEST 2010


New submission from James <purpleidea at gmail.com>:

Attempting to change the working directory and then import based on that change has no effect. Import seems impossible. Attached is tarball example. As seen below, bar1.py can import foo from src, however bar2.py bar3.py and bar4.py cannot, despite their respective scripts changing their cwd. Below is results of a terminal session. Thanks in advance.

james at hostname:~$ tree import_bug/
import_bug/
|-- bar1.py
|-- __init__.py
|-- src
|   |-- foo.py
|   `-- __init__.py
`-- test
    |-- bar2.py
    |-- bar3.py
    |-- bar4.py
    |-- bar5.py
    `-- __init__.py

2 directories, 9 files
james at hostname:~$ cat import_bug/src/foo.py 
# this is foo.py
print('this is foo.py')

james at hostname:~$ cat import_bug/bar1.py 
# this is bar1.py
import os



print(os.getcwd())
from src import foo
print('this is bar1.py')

james at hostname:~$ cat import_bug/test/bar2.py 
# this is bar2.py
import os

os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))

print(os.getcwd())
from src import foo
print('this is bar2.py')

james at hostname:~$ python import_bug/bar1.py 
/home/james
this is foo.py
this is bar1.py
james at hostname:~$ python import_bug/test/bar2.py 
/home/james/import_bug
Traceback (most recent call last):
  File "import_bug/test/bar2.py", line 7, in <module>
    from src import foo
ImportError: No module named src
james at hostname:~$

----------
components: Library (Lib)
files: import_bug.tar
messages: 107403
nosy: purpleidea
priority: normal
severity: normal
status: open
title: import doesn't notice changes to working directory
versions: Python 2.6, Python 3.1
Added file: http://bugs.python.org/file17600/import_bug.tar

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8955>
_______________________________________


More information about the New-bugs-announce mailing list