python - importing parent dir issues -


i created virtualenv foo project , i've problem importing file module in test_file.py

this project directory

foo/ ├── app │   ├── __init__.py │   ├── testfile.py │   ├── tests │   │   ├── __init__.py │   │   └── test_gram.py │   ├── util │   │   ├── file.py │   │   ├── gram.py │   │   ├── __init__.py └── notes 

test_gram.py:

from app.util.file import loaddatafrompickle  listofdict = loaddatafrompickle(".....") = 0 item in listofdict[:50]:     print(item) 

if run test_gram, getting importerror:

traceback (most recent call last):   file "test_gram.py", line 1, in <module>     app.util.file import loaddatafrompickle importerror: no module named 'app 

what doing wrong? need change virtualenv-path foo/app instead of foo?

if test_gram.py in tests folder, import line should be:

from ..util.file import loaddatafrompickle$ 

another option use imp module, suggested instead of appending sys.path (source here, including python 3 version)

import imp  foo = imp.load_source('module.name', '/path/to/file.py') foo.myclass() 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -