I'm a super newb to Python, pipenv, and especially Sublime Text 3. Couldn't find a simple solution to get me started working with pipenv virtual environment and sublime on Windows 10.
This works really well for someone who doesn't have much systems experience.
My setup:
Windows 10 Pro
Python 3.9
Sublime Text 3
Dedicated directory for Python virtual environment 'C:Users\username\VirtualEnvs`
- create a virtual environment using pipenv in a dedicated directory:
pipenv install BestPythonPackage
- from the dedicated directory run:
pipenv shell
- get the virtual environment path; while in the shell run:
pipenv --venv
- open folder in sublime
- create new project:
Project > Save Project As > "New Project Name"
- select
"New Project Name".sublime-project
from file list in left column
- replace contents of that file with the below and save. The path is what you found from running 'pipenv --venv'
{
"folders":
[
{
"path": "C:\\Users\\username\\.virtualenvs\\PythonEnvs-uKL8m4_g",
},
],
"build_systems": [
{
"name": "PYTHON_PIPENV",
"cmd": ["python", "$file"],
}
],
}
Observe the sublime folder name for your dedicated folder has changed to the name of the virtual environment.
Create a 'hello.py' program from the folder.
build the program with Tools > Build System > "PYTHON_PIPENV"
build system now in the list.
Of course, the caveat here is you'd need to do this for any new virtual environment. Some of the other solutions provided will dynamically update. Those were/are over my head at the moment. This is a simple solution.
'folders' section tells sublime what directory to look at
'build_systems' gives a name for the new config, and tells sublime to run 'python' on whatever file you have open.