Installing and running VS Code

Hi, I need help in getting VS Code to run python code correctly.

I had installed it from the Zorin app store, but ran into the same issues described here:

So I installed the deb package from the Microsoft link by just downloading and using the file manager to run/install it. However, it is still not running python correctly - namely some packages, while it exists, cannot be accessed. I believe it has something to do with the "environment it is run in."

Apologies for the lack of correct jargon here. I am migrating my python from Win10 to Zorin, and from spyder to VS Code.

How do you create this environment so that I can install python packages that VSCode can access?

I am also experiencing this issue in Jupyter notebook.

Many thanks in advance for you help.
SJ

Here is a guide how to install vs code:

Perhaps you need a newer version of python that is installed in Zorin. You can use docker or pyenv. Take a look at this thread:

Maybe a distribution with rolling release or a non LTS version that offers newer packages of python and glib is better for your needs.

It would help to know the actual error message. Could you also detail what steps are you taking when this error happens?

If you're using VSCode then you're using the Microsoft's Python extension. You can see how to make it work in this guide:

Note, however, that using a virtual environment will not change the actual Python interpreter version. If you issue is due to this version mismatch, you'll have to install additional ones. We can't advice without knowing more about this, though.

Thank you @zenzen and @Forpli for your quick replies and help which provided some hints!

In terms of error messages as @zenzen asked, there were none other than VS Code flagging me that a package was not installed during the debugging process, hence my initial posting that certain packages were not being accessed.

In my investigation, I discovered that I had a global and local installs of python packages based on pip3 list compared to pip3 list --user. I dont know how a separation happened as I thought each time I was running the package installs from my home/user.

So, following the instructions in the link in my original post, I created a virtual environment my_env where I installed all the packages I needed.

I then pointed my VS Code interpreter to that virtual environment location: (CTL+SHIFT+P) which allowed me to navigate to the directory /home/user/my_env/bin/ of the virtual environment and choose the python3 interpreter. There was a python3.10 interpreter I could have selected but so far the python3 works.

Maybe the step of creating the virtual environment was not necessary and all I needed to do was to point my interpreter to the local interpreter ?

Thanks!

2 Likes

Using a virtual environment is usually preferable because then you can install packages that stay contained in one place. But, you also have to activate the virtual environment in order to be able to use it, both for installing packages locally to that environment and to use it's interpreter.

My guess is that you must've installed something following instructions that created the environment, but as you said VS Code needs to be told that it exists and to use it (i.e., activate it).

But, if it works now, don't touch it! :smiley:

1 Like