I'm trying to import code from a local module into a pweave document, and I can't get it to work.
I have the following files
- foo.pmd
- bar.py
- __init__.py
Contents of foo.pmd:
```python
import bar
bar.foobar()
```
Contents of bar.py:
def foobar():
return(1)
Then I run pweave foo.md
and the output fails:
---------------------------------------------------------------------------ImportError
Traceback (most recent call last)<ipython-input-1-1c3509f6dae7> in <module>()
----> 1 import bar
2 bar.foobar()
ImportError: No module named
'bar'
I think this should work? Or am I trying to do something that's not possible?
I had the same problem. My solution:
I think the problem is, that the current working directory is not in the Python-Path where Python looks for modules (I have no idea why this problem only occurs with pweave).
gives you the "current working directory" and
adds this directory to the Python-path (only for this session! So you don't have to delete it at the end).