Visual Studio Code: Difference between revisions
Brian Wilson (talk | contribs) mNo edit summary |
Brian Wilson (talk | contribs) |
||
Line 14: | Line 14: | ||
On [[Murre]] this was a problem. It's seeing non-existent ArcMap pythons and the emacs python but not the one WindowsApps installed. | 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. | 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 | python3 -m venv .venv | ||
=== The better way, adjust settings === | |||
This is a better solution, first put the commonly used variables into your user settings, | |||
File -> Preferences -> Settings -> User -> Extensions -> Python | |||
This assumes you are using ArcGIS Pro. | |||
Python: Conda path: "C:/Program Files/ArcGIS/Pro/bin/Python/Scripts/conda.exe" | |||
Python: Venv folders: "AppData/Local/ESRI/conda/envs" | |||
Reload VSCode. Then, add this to your workspace .vscode/settings.json: | |||
"python.pythonPath": "${python.venvPath}/arcgispro-py3-vscode/python.exe" | |||
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") | |||
== Remote development == | == Remote development == |
Revision as of 02:36, 30 March 2020
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.
It's not finding Python!!
Here is a doc telling where it looks.
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
The better way, adjust settings
This is a better solution, first put the commonly used variables into your user settings, File -> Preferences -> Settings -> User -> Extensions -> Python
This assumes you are using ArcGIS Pro.
Python: Conda path: "C:/Program Files/ArcGIS/Pro/bin/Python/Scripts/conda.exe" Python: Venv folders: "AppData/Local/ESRI/conda/envs"
Reload VSCode. Then, add this to your workspace .vscode/settings.json:
"python.pythonPath": "${python.venvPath}/arcgispro-py3-vscode/python.exe"
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")
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