-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VSCode integrated terminal is not inheriting the virtualenv created by pipenv #660
Comments
We're tracking pipenv support over in #404 . |
I'm sorry, I don't think this is the same as #404. I believe this is going to happen for any virtualenv (even without pipenv involved).. This is preventing me from using pipenv even without official support from vscode. How do people use vscode with virtual environments? Looks broken right now to me. |
@tjaffri the problem is simple. |
@DonJayamanne ah ok... thanks. That's helpful! |
@tjaffri I was having the same issue that you originally described above, but couldn't decipher the answer for a long time. Posting here in case others are still struggling with this. My interpretation (and the only way I have made pipenv work with VS Code) is that you must make sure that you have not already activated the virtual environment in your Terminal with
Please correct me if you have a different interpretation of the answer, or found another way to make pipenv work with VS Code |
@ptiger10 mind opening a new issue about trying to detect when the user ran |
Environment data
VS Code version: 1.19.3
Python Extension version: 3.6.4
Python Version: 3
OS and version: MacOS High Sierra 10.13.3
Pipenv version 9.0.1 installed via brew install pipenv
Actual behavior
When I create a virtualenv via pipenv (using pipenv shell) everything works in Terminal. Specifically,
which python
returns a path to python in the virtual env, e.g./Users/tjaffri/.local/share/virtualenvs/hello-world-AxAtxCb5/bin/python
.Next, I launch vscode from inside the virtualenv using
code .
. I bring up the integrated terminal inside vscode and now it seems that vscode is not inheriting the virtualenv correctly. Specifically,which python
returns a path to the system python/usr/bin/python
.Note that my vscode settings are completely empty (both workspace and user), so they are using default values for pythonPath etc.
When I try to do
pipenv shell
inside the vscode integrated terminal, I get the following output indicating that the virtualenv is active (but for some reason the python being used is still the system python)Taqis-MacBook-Pro:hello-world tjaffri$ pipenv shell Shell for /Users/tjaffri/.local/share/virtualenvs/hello-world-AxAtxCb5 already activated. No action taken to avoid nested environments.
When I run the script in the integrated terminal via
python3 hello.py
(I have to use python3 rather than python due to the aforementioned issue) then there are problems with imported modules. Since the python3 being used is also the system python3 inside the integrated terminal, any modules installed via pipenv e.g.pipenv install beautifulsoup4
are not found and cannot be imported.Note that when I run the same
python3 hello.py
outside the integrated terminal, i.e. in the pipenv shell in Terminal everything works correctly.Expected behavior
Pipenv created virtual environment should inherit into the vscode integrated terminal, when vscode is launched from inside a virtual environment.
Specifically, the python from inside the virtual environment should be used, so that imported modules in the virtual environment resolve correctly.
Steps to reproduce:
The text was updated successfully, but these errors were encountered: