Using Uplink with VS Code

I’m trying to import my python code that I have written using Visual Studio Code into ANvil using Uplink.

I have copied and pasted the ‘pip install anvil-uplink’ command in the terminal of Visual Studio Code as well as my computer’s terminal. However, every time I run my code in VS Code the ‘import anvil.server’ line gives an error saying ‘no module named anvil’.

Does anyone know why this might be and how to resolve this issue?

Thanks!

This is a bit of a guess, but maybe you have installed the library somewhere VSCode can’t see it. Possibly a virtual environment?

I’m only partially competent in VSCode, but I tend not to install libraries using the VSCode terminal but rather from the command line (in my case, a bash terminal) opened from outside of VSCode.

Also, I tend not to run from within VSCode either, again preferring to launch from the CLI outside. So my advice might not be too much use to you.

I’ll bet that’s the reason, though.

By this, do you mean you want to run call a python script, you have written in VS Code, from Anvil? If yes, then Uplink is what you need.
Your error seems to indicate, that the anvil-uplink package was not installed into the python environment, that VS Code is running. Are you using virtual environments?
If not, perhaps Pip installed the Uplink package into a different python version, than what you are using to run your python script.
In either case, we need more information about what your setup looks like, in order to provide more info.

If you start a python REPL (by typing python or python3 in a commandline or terminal), can you import anvil.server

If you are trying to get use VS Code as a IDE for developing your Anvil app, git can use Git, to pull and push to and from Anvils servers. See this guide for more information - especially Level 6.