0

I am trying to run my python code from command line instead of from my IDE. I have cloned my project from git, and made a python 3 virtual env. I have activated my venv and commands like python --version correctly print the python version in my venv (as apposed to the version I would get running the same command outside the venv, which is different in my case) so I know I am using venv right. Once in the activated venv, I pip install my 3rd party packages from a requirments.txt file with pip pip install -r requirements.txt but I am still having trouble running my code. Here is my directory layout:

project_folder
├── env_vars
|   ├── __init__.py
|   └── env_vars.py
|
├── tests
|   ├── __init__.py
|   └── test.py
|
└── __init__.py

and I am trying to run test.py which has imports that look like:

import os  # python built in, gets past this line no problem
from 3rd_praty_lib import 3rd_party_thing  # this is a library I installed with pip, again gets past this line no problem
from env_vars import env_vars  # <- this is where the failure happens. referencing my own code

So basically my issue is:

when in the tests directory I use the command python test.py and I get this error:

 File "test.py", line 3, in <module>
    from env_vars import env_vars
ModuleNotFoundError: No module named 'env_vars'
Rosey
  • 739
  • 1
  • 12
  • 27

1 Answers1

0

You should had your package to the python path

import sys
sys.path.insert(0, "/path/to/your/package_or_module")
  • This whole time I thought "python path" was just referring to the "path" env var, and not an env var literally called "python path" – Rosey Jun 26 '19 at 14:44