'How to get VScode Integrated Terminal Virtual Environment working?
I have completed a few courses online in Python and recently started a new course in Django. Previously I always used a virtual environment but would activate the environment myself, but in the course I am working through via Code with Mosh he shows a way to have VSCode activate the environment automatically in the terminal.
I tried to follow along but am having a hard time getting this to work. First I tried following Mosh’s steps by locating the virtual environment location in terminal on the Mac using: pipenv --venv
and this returned the location as /Users/lewpiper/.local/share/virtualenvs/storefront-7UYLLetM
on my Mac. I then tried to to use this in the command palette with bin/python
on the end of the path in VSCode to select the python interpreter and it didn’t seem to work. It seems like it didn't create the VSCode folder or JSON file that I saw in the lessons I was watching.
Then I tried to edit the workspace settings in VSCode and add the following "python.pythonPath": "/Users/lewpiper/.local/share/virtualenvs/storefront-7UYLLetM"
to match the VSCode file structure and again I am running into it not launching the terminal window with the virtual environment activated.
Now when I click play in VSCode I get the following message “ImportError: Couldn’t import Django. Are you sure it’s installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?”
Any help or direction to guide me in the right direction would be very much appreciated.
Solution 1:[1]
I realized after writing my question out and reading it back to myself that I never added /bin/python
to the end of the path in the JSON file. That fixed it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Lew |