Using Windows, I cannot get my python script to use my virtual environment when executing in a text editor (Atom).
I know how to use the command line to get my script to use my virtual environment (by activating my virtual environment and running the script) but I want to be able to work in the text editor.
I tried to include the shebang #!/usr/bin/env python
to indicate to my script to use the virtual environment (as suggested here), but Windows might not actually support shebangs (from here and here). I attempted to directly state the path of my virtual environment but it wasn't clear how to do that (I tried variations of #!"C:\Users\...\my_project\venv\Scripts\python.exe"
)
Note that my file structure is a folder (my_project) containing two folders, venv (my virtual environment) and my_code (which contains my_script.py).
The following script prints paths from my virtual environment when executed from the command line but paths from my system when executed from the text editor. Additionally, I have installed sklearn globally but not in my virtual environment, and sklearn fails to import when executed from the command line (as desired) but imports when executed from the text editor (not desired).
#!/usr/bin/env python
import sys
print(sys.path)
from sklearn.cluster import KMeans
How can I get my script to recognize the virtual environment I want to use?