Skip to content
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

Unable to Find Pipenv Virtual Environment in VSCode Jupyter Notebook #23260

Open
DonJayamanne opened this issue Apr 18, 2024 · 12 comments
Open
Assignees
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality needs PR Ready to be worked on

Comments

@DonJayamanne
Copy link

Discussed in microsoft/vscode-jupyter#15564

Originally posted by LiPingYen April 18, 2024
I'm encountering an issue while using Jupyter Notebook within VSCode where I can't locate the Python virtual environment created by pipenv.

When I run a Python script, the pipenv virtual environment is found without any problem. Currently, it seems that when selecting the Jupyter kernel, VSCode can successfully locate the base and conda-related virtual environments, but it fails to find the one created by pipenv.

I've searched for relevant articles but haven't found a suitable solution. Has anyone experienced a similar situation and found a resolution? Any insights or solutions would be greatly appreciated.

@DonJayamanne DonJayamanne added the info-needed Issue requires more information from poster label Apr 18, 2024
@DonJayamanne
Copy link
Author

Do you see the pipenv environment when using the command Python: Select Interpereter

@DonJayamanne
Copy link
Author

Hi @DonJayamanne,

Yes, the pipenv environment is shown when I search in Python: Select Interpereter.

  1. Python environment in Python: Select Interpereter:
CleanShot 2024-04-18 at 22 34 44@2x
  1. Python environment in Jupyter: Select Intepreter to start jupyter notebook server:

CleanShot 2024-04-18 at 22 34 22@2x

@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-jupyter Apr 18, 2024
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Apr 18, 2024
@DonJayamanne
Copy link
Author

@karthiknadig I have seen such issues in the past, environments setup in settings are not visible in the environments API.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Apr 18, 2024
@karthiknadig karthiknadig self-assigned this Apr 22, 2024
@euisuk-chung
Copy link

Any updates?

@karthiknadig
Copy link
Member

@euisuk-chung I am still investigating this, sorry for the lack of response. Was the pipenv environment created for this project or for a different project?

@DonJayamanne For pipenv the environment created by pipenv is mostly associated with a project folder. The hash part in the path python-<hash> is based on the project that the pipenv is bound to.
image

We don't show environments that are (from the tooling perspective) not associated with the project. The select interpreter command from python shows the setting value python.defaultInterpreterPath which is where you are seeing, and not an actual detection in the list of environments. Selecting it is equivalent to entering the path to the interpreter manually.

Re-using the same environment for different projects goes against the recommendations of how some of these tools handle the environment. hatch is another tool that using hash based environment association.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label May 2, 2024
@LiPingYen
Copy link

LiPingYen commented May 2, 2024

Hi @karthiknadig, I am the original author from microsoft/vscode-jupyter#15564 who face the issue. Thanks for your investigation. Hope we can fix this issue in the short run.

I created a pipenv folder on computer desktop, and the python Interpreter and related files will be put in the sub-folder of ~/.local/share/virtualenvs. I set this pipenv environment as a default python interpreter when I run python script through the setting in vscode. So from the first screen shot, you can see the python interpreter path shown.

However when I ran the jupyter notebook in vscode, I couldn't find the same python interpreter from pipenv I created.
I assume that maybe there is a way to create a setting part in vscode to set a default python interpreter for jupyter notebook.
Since I am not quite familiar with the development for vscode setting, I am not sure whether this is the possible way to solve this issue.

Hope the above information can give you some idea.
Thanks for your attention to this issue @karthiknadig.

@karthiknadig
Copy link
Member

@LiPingYen typically you would have a different virtual environment for each of your workspace. Actually the best way that you would do this is using PIPENV_VENV_IN_PROJECT environment variable. This makes sure you can have a .venv in your project and they are all isolated. see here https://pipenv.pypa.io/en/latest/virtualenv.html#custom-virtual-environment-location .

Having a single global environment can be problematic over time. As more and more packages get installed, it can leave the environment in a state where it may not be usable in some projects. The added benefit of having the .venv in your project is when you get rid of the project the environment also goes away without leaving stray environments like when using a global location to create environments.

Please give the PIPENV_VENV_IN_PROJECT a try. Meanwhile, we will discuss with the team on how we want to handle these scenarios.

@LiPingYen
Copy link

LiPingYen commented May 3, 2024

@karthiknadig thanks for your recommendation. I know creating isolated virtual environment can keep each project without interfering each other. However, in my scenario, I only need to handle one pipenv virtual environment to run all the projects. This can let me easily check and update the package in the only one virtual environment. As an individual developer, one global virtual environment can run all my project and manage the virtual environment on my own. Also pipenv can use the same syntax in terminal and cmd to manage the virtual environment crossing different OS. I have already abandoned the virtualenv since I start using pipenv.

Curiously, why vscode can detect Conda virtual environment, but it can't find pipenv? #23260 (comment)

I still hope vscode can Integrate the pipenv in the option of virtual environment. This may benefit more python user who run their project in vscode.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label May 3, 2024
@fsimonjetz
Copy link

I have encountered the same issue for a while. Curiously, the environments created with pipenv used to be there in the past but at some point a few weeks ago they disappeared. For me, the pipenv environments don't show up when I Select interpreter either. Unfortunately I don't know when exactly it started.

@LiPingYen
Copy link

Hi @karthiknadig, will VSCode support pipenv for Jupyter Notebook shortly?

@amanchaudhary-95
Copy link

I've the same issue. I can't use the same virtual environment in different projects. It kind of creates redundant virtual environments for each project. If I use the older version of the extension then only it is allowing to see the other virtual environments.

@karthiknadig karthiknadig removed their assignment Aug 23, 2024
@karthiknadig karthiknadig added feature-request Request for new features or functionality area-environments Features relating to handling interpreter environments needs PR Ready to be worked on and removed triage-needed Needs assignment to the proper sub-team labels Aug 23, 2024
@aradley
Copy link

aradley commented Dec 16, 2024

I'm having a similar issue. My pipenv environments were identifiable and working for the first few weeks of using Jupyter notebooks in VScode, and suddenly they can no longer be found/used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality needs PR Ready to be worked on
Projects
None yet
Development

No branches or pull requests

7 participants