Visual Studio Code
where does it ever end? Komodo -> Microsoft Visual Studio -> Atom -> Visual Studio Code
I am now learning Visual Studio Code
I am currently using VSC to edit Python to create Geoprocessing scripts that I can run in Docker containers.
Settings
It's not finding Python!!
Here is a doc telling where it looks.
1 Work around the problem
On Murre this was a problem. It's seeing non-existent ArcMap pythons and the emacs python but not the one WindowsApps installed. But the Powershell it launches can see it. So in the Powershell I created a virtual environment and told it to use that.
This works because it will search the current workspace.
python3 -m venv .venv
2 Better way, adjust settings
First set a local environment variable to point to where your environment lives. Mine is here.
CONDA_ENVS_PATH="C:/Users/brian/AppData/Local/ESRI/conda/envs"
Add put the commonly used variables into your user settings, File -> Preferences -> Settings -> User -> Extensions -> Python -> Conda Path
"C:/Program Files/ArcGIS/Pro/bin/Python/Scripts/conda.exe"
Reload VSCode. Intellisense should work for you now too.
Now when you select a Python version, the right ones should appear. Make sure you pick the right environment (for me I named it "arcgispro-py3-vscode")
If you do it this way you should be able to use conda correctly from a bash shell too.
(base) brian@murre:~$ conda env list # conda environments: # base * C:\Program Files\ArcGIS\Pro\bin\Python arcgispro-py3 C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3 arcgispro-py3-vscode C:\Users\brian\AppData\Local\ESRI\conda\envs\arcgispro-py3-vscode conda activate arcgispro-py3-vscode (arcgispro-py3-vscode) brian@murre:~$ python --version Python 3.6.10 :: Anaconda, Inc.
and so on...
ESRI .PYT files are not treated as Python
I put this in my global settings.json file (F1 File:Associations)
"files.associations": {"*.pyt": "python"}
Remote development
I've now tried this tutorial and learned it works. Python in a Container I got a simple Flask app running and then switched to running even simpler Python scripts in the container.
When I needed to add volume support I discovered this page: VS Code Remote Development It explains the Remote Development extension pack.
- I can use Remote - SSH to treat a remote machine (say, Bellman) as the host for a remote project. (* As recommended by John Sullivan.)
- I can use Remote - Containers to treat a Docker container as the host.
- I can use Remote - WSL too but I don't use Windows Subsystem for Linux currently.
Docker containers
I can keep the code on the local file system or in the container.
My first tests I used the Dockerfile to load my code into the image. It worked fine.
More options:
- clone from github into a running container
- keep code in a volume mounted on the container
Using a volume seems to make the most sense to me. In that setting I can still easily use command line git.
There is a sample based on python, it starts a Debian container and puts a Bash prompt into a Terminal window. It connects when you do F5. Your code is accessible on the local filesystem and in the mounted volume in the container.
git clone https://github.com/Microsoft/vscode-remote-try-python