3
I received an import error while debugging main.py. My IDE Visual Studio Code seems having problem recognizing my TREE structure (shown below), since the following worked outside of VSC:
- Run in virtual environment:
pipenv run python3.7 -m pset_1
Debug in virtual environment:
pipenv run python3.7 -m pdb pset_1
Exception has occurred: ImportError attempted relative import with no known parent package File "/home/hoang/Documents/E29/pset1/2019sp-pset-1-nhvinh118/pset_1/main.py", line 4, in from .hash_str import get_csci_salt, get_user_id, hash_str File "/usr/local/lib/python3.7/runpy.py", line 85, in _run_code exec(code, run_globals) File "/usr/local/lib/python3.7/runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "/usr/local/lib/python3.7/runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname)
IMPORT statement in __main__.py (module to debug)
from .hash_str import get_csci_salt, get_user_id, hash_str
from .load_data import load_vectors, load_words, load_data
TREE
.
|-- Dockerfile
|-- Pipfile
|-- Pipfile.lock
|-- README.md
|-- __pycache__
| `-- tokenize.cpython-37.pyc
|-- data
| |-- hashed.parquet
| `-- hashed.xlsx
|-- docker-compose.yml
|-- drun_app
|-- pipenvgraph.log
|-- pset_1
| |-- WordEmbedding.py
| |-- __init__.py
| |-- __main__.py
| |-- hash_str.py
| |-- io.py
| |-- load_data.py
| `-- tokenize.py
|-- setup.cfg
`-- tests.py
My two settings.json
(1) /home/hoang/.config/Code/User/settings.json
{
"python.pythonPath": "/home/hoang/anaconda3/bin/python",
"git.enableSmartCommit": true
}
(2) /home/hoang/Documents/E29/pset1/2019sp-pset-1-nhvinh118/.vscode/settings.json
{
<<<<<<< HEAD
"python.pythonPath": "/home/hoang/.local/share/virtualenvs/2019sp-pset-1-nhvinh118-a6Ueu8mF/bin/python",
"~/Documents/E29/pset1/2019sp-pset-1-nhvinh118/pset_1/."
"python.linting.enabled": true
=======
"python.pythonPath": "/home/hoang/.local/share/virtualenvs/2019sp-pset-1-nhvinh118-a6Ueu8mF/bin/python"
>>>>>>> master
}
About my system
- OS: Linux x64 4.15.0-45 generic (Ubuntu 18.04.2 LTS)
- IDE: Visual Studio Code v 1.31.0
- Interpreter: Python 3.7.1