Reputation: 1
Working on a dbt (data build tool) project, I have a python virtual environment with dbt installed and would like the virtual environment to be activated in vscode by the python extension. However, it appears the extension doesn't load until you open a .py file in vscode. As a dbt project, there are no .py files.
As a work-around, I have created an empty .py file to load the extension. Is there some other way to do this, preferably on vscode startup in this particular workspace? Thanks
Upvotes: 0
Views: 674
Reputation: 264
My guess is that you want the virtualenv loaded in order to execute dbt jobs from the vscode shell. Instead of tricking vscode into adding the virtualenv to application’s pythonpath, the user could instead add the virtualenv directory to their system PATH. If they did this, then dbt would also point to the executable in the virtualenv regardless of if the env was loaded or not.
Can I also ask what you plan on using this for. This might help find a better answer.
It seems that I myself am the exception to the rule for almost all 'simple' installation procedures. For some reason, it WAS a path related issue:
I ran brew info python, which outputted a lot of information. At the bottom I found this:
Executable python scripts will be put in:
/usr/local/share/python
so you may want to put "/usr/local/share/python" in your PATH, too.
I added that to my PATH in /etc/launchd.conf and ~/.bashrc and lo and behold:
$ which virtualenv
tells me:
"/usr/local/share/python/virtualenv"
I still don't know why I couldn't find any pointers in the right direction, online, anywhere? Is pip install virtualenv supposed to add to the PATH itself? If so, why not on my system? Why did @bibhas tell me explicitly it was not a path issue?
Thanks to @drew from FishTown Analytics for the help on this one.
Upvotes: 1
Reputation: 2763
Closest thing that I've found is to set your directory up as follows:
dbt-project-dir
| .vscode
> settings.json
| analysis
| data
| macros
| models
| tests
.gitignore
dbt_project.yml
README.md
Where the contents of the settings.json is:
{
"python.pythonPath": "C:\\tools\\miniconda3\\envs\\dbt\\python.exe"
}
Then from there, open your python file (or use command palette to select interpreter) like normal so that you have your environment active via the python extension:
Then save your workspace via the file menu to your .vscode directory.
That's as far as I've gotten so far - I'm still experimenting with alias launch run flags to pass commands to the
Upvotes: 0